diff --git a/terraform_fmt.sh b/terraform_fmt.sh index 17aceda17..dad9a699b 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