bazel: add terraform fmt to //:tidy target (#1501)

Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com>
This commit is contained in:
Paul Meyer 2023-03-22 13:14:35 -04:00 committed by GitHub
parent 7d899d7aa5
commit b65b09fd9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View file

@ -195,6 +195,18 @@ sh_template(
template = "tf.sh.in", template = "tf.sh.in",
) )
sh_template(
name = "terraform_fmt",
data = [
":com_github_hashicorp_terraform",
],
substitutions = {
"@@MODE@@": "format",
"@@TERRAFORM@@": "$(rootpath :com_github_hashicorp_terraform)",
},
template = "tf.sh.in",
)
multirun( multirun(
name = "tidy", name = "tidy",
commands = [ commands = [
@ -204,6 +216,7 @@ multirun(
":gazelle_update_repos", ":gazelle_update_repos",
":gazelle_generate", ":gazelle_generate",
":buildifier_fix", ":buildifier_fix",
":terraform_fmt",
], ],
jobs = 1, # execute sequentially jobs = 1, # execute sequentially
visibility = ["//visibility:public"], visibility = ["//visibility:public"],

View file

@ -57,6 +57,14 @@ case ${mode} in
done done
;; ;;
"format")
echo "Formatting the following Terraform modules:"
for module in "${terraformModules[@]}"; do
echo " ${module}"
${terraform} -chdir="${module}" fmt -recursive > /dev/null
done
;;
"generate") "generate")
echo "Formatting and generating lock files for the following Terraform modules:" echo "Formatting and generating lock files for the following Terraform modules:"
for script in "${terraformModules[@]}"; do for script in "${terraformModules[@]}"; do
@ -70,7 +78,6 @@ case ${mode} in
${terraform} -chdir="${module}" providers lock -platform=darwin_arm64 > /dev/null ${terraform} -chdir="${module}" providers lock -platform=darwin_arm64 > /dev/null
${terraform} -chdir="${module}" providers lock -platform=darwin_amd64 > /dev/null ${terraform} -chdir="${module}" providers lock -platform=darwin_amd64 > /dev/null
${terraform} -chdir="${module}" providers lock -platform=windows_amd64 > /dev/null ${terraform} -chdir="${module}" providers lock -platform=windows_amd64 > /dev/null
${terraform} -chdir="${module}" fmt -recursive > /dev/null
rm -rf "${module}/.terraform" rm -rf "${module}/.terraform"
done done
;; ;;