Skip to content

Commit

Permalink
Store and return last failure from validate vs exit on first failure (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
davidalger authored Dec 9, 2020
1 parent edda9e3 commit 39887f3
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions hooks/terraform-validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,18 @@ set -e
# workaround to allow GitHub Desktop to work, add this (hopefully harmless) setting here.
export PATH=$PATH:/usr/local/bin

# Disable output not usually helpful when running in automation (such as guidance to run plan after init)
export TF_IN_AUTOMATION=1

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

for dir in $(echo "$@" | xargs -n1 dirname | sort -u | uniq); do
echo "--> Running 'terraform validate' in directory '$dir'"
pushd "$dir" >/dev/null
terraform init -backend=false
terraform validate
terraform init -backend=false || VALIDATE_ERROR=$?
terraform validate || VALIDATE_ERROR=$?
popd >/dev/null
done

exit ${VALIDATE_ERROR}

0 comments on commit 39887f3

Please sign in to comment.