Skip to content
Open
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
17 changes: 15 additions & 2 deletions scripts/terraform_validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,24 @@ validate_variable_names() {

validate_terraform_directory() {
local dir="$1"
local rc=0
echo "Running \`terraform validate\` in $dir"
pushd "$dir" > /dev/null
terraform init -upgrade
terraform validate

# `terraform validate` requires modules to be installed first. If
# `terraform init` fails (for example a bad module source), skip validate
# so we surface the real init error instead of misleading
# "Module not installed" errors.
if ! terraform init -upgrade; then
echo " ERROR: \`terraform init\` failed in $dir" >&2
popd > /dev/null
return 1
fi

terraform validate || rc=1

popd > /dev/null
return "$rc"
}

main() {
Expand Down
Loading