Skip to content

Commit

Permalink
Update terraform-fmt to match terraform-validate (#46)
Browse files Browse the repository at this point in the history
This PR updates the `terraform-fmt` hook as follows:

1. Run with `-diff -check` so the differences are printed, rather than made on disk.
1. Instead of exiting on the first error, save the exit codes, and print out all `fmt` errors before exiting.

These changes are very similar to #45.
  • Loading branch information
brikis98 authored Dec 10, 2020
1 parent 39887f3 commit e9250bd
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions hooks/terraform-fmt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ set -e
# workaround to allow GitHub Desktop to work, add this (hopefully harmless) setting here.
export PATH=$PATH:/usr/local/bin

# Store and return last failure from fmt so this can validate every directory passed before exiting
FMT_ERROR=0

for file in "$@"; do
pushd "$(dirname "$file")" >/dev/null
terraform fmt -write=true "$(basename "$file")"
popd >/dev/null
terraform fmt -diff -check "$file" || FMT_ERROR=$?
done

exit ${FMT_ERROR}

0 comments on commit e9250bd

Please sign in to comment.