From b0d43204ca5dd994dd0b9f2a4c793ff807cfc303 Mon Sep 17 00:00:00 2001 From: Anton Babenko Date: Tue, 6 Mar 2018 13:58:03 +0100 Subject: [PATCH] Format tfvars files explicitely, because terraform fmt ignores them (#9) --- terraform_fmt.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/terraform_fmt.sh b/terraform_fmt.sh index 17aceda..dad9a69 100755 --- a/terraform_fmt.sh +++ b/terraform_fmt.sh @@ -2,10 +2,17 @@ set -e declare -a paths +declare -a tfvars_files + index=0 for file_with_path in "$@"; do paths[index]=$(dirname "$file_with_path") + + if [[ "$file_with_path" == *".tfvars" ]]; then + tfvars_files+=("$file_with_path") + fi + let "index+=1" done @@ -14,3 +21,8 @@ for path_uniq in $(echo "${paths[*]}" | tr ' ' '\n' | sort -u); do terraform fmt popd > /dev/null done + +# terraform.tfvars are excluded by `terraform fmt` +for tfvars_file in "${tfvars_files[@]}"; do + terraform fmt "$tfvars_file" +done