From eadb49b7d3426f9627973f4a9235e315f1de5aab Mon Sep 17 00:00:00 2001 From: Adar Nimrod <nimrod@shore.co.il> Date: Wed, 26 May 2021 22:18:39 +0300 Subject: [PATCH] Terraform 0.15. Terraform 0.15 removed the option to specify the directory as an argument. Instead it offers a new optional parameter. Instead of dealing with different versions in specific ways, just cd to that directory. --- tff | 5 ++++- tfv | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tff b/tff index cf69077..f0a4998 100755 --- a/tff +++ b/tff @@ -3,7 +3,10 @@ set -eu command -v terraform >/dev/null || { echo "Can't find the terraform binary, aborting." >&2; exit 1; } +original_pwd="$PWD" for i in "$@" do - terraform fmt "$(dirname "$i")" || true + cd "$(dirname "$i")" + terraform fmt || true + cd "$original_pwd" done diff --git a/tfv b/tfv index 5d9f1b6..dbc861e 100755 --- a/tfv +++ b/tfv @@ -6,10 +6,13 @@ command -v terraform >/dev/null || { echo "Can't find the terraform binary, abor export TF_INPUT='0' export TF_IN_AUTOMATION='1' +original_pwd="$PWD" for i in "$@" do - terraform init -backend=false "$(dirname "$i")" || { code='1'; continue; } - terraform validate "$(dirname "$i")" || code='1' + cd "$(dirname "$i")" + terraform init -backend=false || { code='1'; continue; } + terraform validate || code='1' + cd "$original_pwd" done exit "${code:-0}" -- GitLab