Skip to content

Commit

Permalink
Merge pull request #47 from cisagov/improvement/adjust_packer_validat…
Browse files Browse the repository at this point in the history
…e_hook

Adjust the functionality of the `packer_validate` hook
  • Loading branch information
mcdonnnj authored Oct 10, 2024
2 parents 2621af2 + ebbf8be commit d635a17
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ behavior can be overridden by changing the arguments passed to the hook.
This hook checks that a Packer configuration is valid by running `packer validate`
against any directory that houses `.pkr.hcl` files.

> [!NOTE]
> The hook will change to each directory and run `packer init` before running
> `packer validate`.
## Usage ##

```yaml
repos:
- repo: https://github.com/cisagov/pre-commit-packer
rev: v0.1.0
rev: v0.2.0
hooks:
- id: packer_fmt
- id: packer_validate
Expand Down
2 changes: 1 addition & 1 deletion config/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.0
0.2.0
5 changes: 4 additions & 1 deletion hooks/packer_validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ util::get_unique_directory_paths "${FILES[@]}"
error=0

for path in "${UNIQUE_PATHS[@]}"; do
if ! packer validate "${ARGS[@]}" -- "$path"; then
pushd "$path" > /dev/null

packer init . > /dev/null
if ! packer validate "${ARGS[@]}" .; then
error=1
echo
echo "Failed path: $path"
Expand Down

0 comments on commit d635a17

Please sign in to comment.