Skip to content
Snippets Groups Projects
Commit 2f72a978 authored by nimrod's avatar nimrod
Browse files

fixup! Packer hooks.

parent 1d2851f1
No related branches found
No related tags found
No related merge requests found
Pipeline #2491 passed
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
description: Fix known backwards incompatibilities in Packer templates description: Fix known backwards incompatibilities in Packer templates
language: python language: python
entry: packer-fix entry: packer-fix
types_or: [json, hcl] types_or: [json]
- id: packer-fmt - id: packer-fmt
name: Format Packer templates name: Format Packer templates
......
...@@ -55,7 +55,8 @@ Requires an installed `terraform`. ...@@ -55,7 +55,8 @@ Requires an installed `terraform`.
### `packer-fix` ### `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` ### `packer-fmt`
......
...@@ -6,6 +6,17 @@ import sys ...@@ -6,6 +6,17 @@ import sys
import hooks.utils 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(): def main():
"""Main entrypoint.""" """Main entrypoint."""
parser = argparse.ArgumentParser(description=__doc__) parser = argparse.ArgumentParser(description=__doc__)
...@@ -13,7 +24,7 @@ def main(): ...@@ -13,7 +24,7 @@ def main():
args = parser.parse_args() args = parser.parse_args()
hooks.utils.check_executable("packer") hooks.utils.check_executable("packer")
return hooks.utils.bulk_check( return hooks.utils.bulk_check(
lambda x: hooks.utils.check_file(["packer", "validate", x]), packer_validate,
args.file, args.file,
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment