Skip to content

Commit a787da3

Browse files
committed
Store and return last failure from validate vs exit on first failure
1 parent edda9e3 commit a787da3

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

hooks/terraform-validate.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,18 @@ 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+
# Disable output not usually helpful when running in automation (such as guidance to run plan after init)
11+
export TF_IN_AUTOMATION=1
12+
13+
# Store and return last failure from validate so this can validate every directory passed before exiting
14+
VALIDATE_ERROR=0
15+
1016
for dir in $(echo "$@" | xargs -n1 dirname | sort -u | uniq); do
17+
echo "--> Running 'terraform validate' in directory '$dir'"
1118
pushd "$dir" >/dev/null
12-
terraform init -backend=false
13-
terraform validate
19+
terraform init -backend=false || VALIDATE_ERROR=$?
20+
terraform validate || VALIDATE_ERROR=$?
1421
popd >/dev/null
1522
done
23+
24+
exit ${VALIDATE_ERROR}

0 commit comments

Comments
 (0)