Commit 2f72a978 authored by nimrod's avatar nimrod
Browse files

fixup! Packer hooks.

parent 1d2851f1
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@
  description: Fix known backwards incompatibilities in Packer templates
  language: python
  entry: packer-fix
  types_or: [json, hcl]
  types_or: [json]

- id: packer-fmt
  name: Format Packer templates
+2 −1
Original line number Diff line number Diff line
@@ -55,7 +55,8 @@ Requires an installed `terraform`.

### `packer-fix`

Fix known backwards incompatibilities in Packer templates.
Fix known backwards incompatibilities in Packer templates (just JSON files,
until support for HCL files is added in Packer).

### `packer-fmt`

+12 −1
Original line number Diff line number Diff line
@@ -6,6 +6,17 @@ import sys
import hooks.utils


def packer_validate(file):
    """Validate a Packer template.

    Run init when needed.
    """
    if str(file).endswith(".pkr.hcl") or str(file).endswith(".pkr.json"):
        if hooks.utils.check_file(["packer", "init", file]) > 0:
            return 1
    return hooks.utils.check_file(["packer", "validate", file])


def main():
    """Main entrypoint."""
    parser = argparse.ArgumentParser(description=__doc__)
@@ -13,7 +24,7 @@ def main():
    args = parser.parse_args()
    hooks.utils.check_executable("packer")
    return hooks.utils.bulk_check(
        lambda x: hooks.utils.check_file(["packer", "validate", x]),
        packer_validate,
        args.file,
    )