Skip to content

Commit e9250bd

Browse files
authored
Update terraform-fmt to match terraform-validate (gruntwork-io#46)
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 gruntwork-io#45.
1 parent 39887f3 commit e9250bd

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

hooks/terraform-fmt.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ set -e
77
# workaround to allow GitHub Desktop to work, add this (hopefully harmless) setting here.
88
export PATH=$PATH:/usr/local/bin
99

10+
# Store and return last failure from fmt so this can validate every directory passed before exiting
11+
FMT_ERROR=0
12+
1013
for file in "$@"; do
11-
pushd "$(dirname "$file")" >/dev/null
12-
terraform fmt -write=true "$(basename "$file")"
13-
popd >/dev/null
14+
terraform fmt -diff -check "$file" || FMT_ERROR=$?
1415
done
16+
17+
exit ${FMT_ERROR}

0 commit comments

Comments
 (0)