Skip to content
Snippets Groups Projects
Commit 0a6eb61e authored by nimrod's avatar nimrod
Browse files

Handle Terraform 0.15 or later.

You can't specify the directory as an argument, instead use the -chdir
global parameter. The main thing is getting the version correctly.
parent 58225fae
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,20 @@ set -eu
command -v terraform >/dev/null || { echo "Can't find the terraform binary, aborting." >&2; exit 1; }
version="$(terraform version | sed --silent 's/Terraform v\([0-9]*\)\.\([0-9]*\)\.[0-9]*$/\1.\2/p')"
major="$(echo "$version" | cut -d '.' -f 1)"
minor="$(echo "$version" | cut -d '.' -f 2)"
if [ "$major" -gt '0' ] || [ "$minor" -gt '14' ]
then
post0_14='1'
fi
for i in "$@"
do
terraform fmt "$(dirname "$i")" || true
if [ -n "${post0_14:-}" ]
then
terraform -chdir="$(dirname "$i")" fmt || true
else
terraform fmt "$(dirname "$i")" || true
fi
done
......@@ -6,10 +6,24 @@ command -v terraform >/dev/null || { echo "Can't find the terraform binary, abor
export TF_INPUT='0'
export TF_IN_AUTOMATION='1'
version="$(terraform version | sed --silent 's/Terraform v\([0-9]*\)\.\([0-9]*\)\.[0-9]*$/\1.\2/p')"
major="$(echo "$version" | cut -d '.' -f 1)"
minor="$(echo "$version" | cut -d '.' -f 2)"
if [ "$major" -gt '0' ] || [ "$minor" -gt '14' ]
then
post0_14='1'
fi
for i in "$@"
do
terraform init -backend=false "$(dirname "$i")" || { code='1'; continue; }
terraform validate "$(dirname "$i")" || code='1'
if [ -n "${post0_14:-}" ]
then
terraform -chdir="$(dirname "$i")" init -backend=false || { code='1'; continue; }
terraform -chdir="$(dirname "$i")" validate || code='1'
else
terraform init -backend=false "$(dirname "$i")" || { code='1'; continue; }
terraform validate "$(dirname "$i")" || code='1'
fi
done
exit "${code:-0}"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment