Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}