diff --git a/bazel/ci/BUILD.bazel b/bazel/ci/BUILD.bazel index b93a90a64..758eb3bcf 100644 --- a/bazel/ci/BUILD.bazel +++ b/bazel/ci/BUILD.bazel @@ -195,6 +195,18 @@ sh_template( 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( name = "tidy", commands = [ @@ -204,6 +216,7 @@ multirun( ":gazelle_update_repos", ":gazelle_generate", ":buildifier_fix", + ":terraform_fmt", ], jobs = 1, # execute sequentially visibility = ["//visibility:public"], diff --git a/bazel/ci/tf.sh.in b/bazel/ci/tf.sh.in index f6875f110..35f73a662 100644 --- a/bazel/ci/tf.sh.in +++ b/bazel/ci/tf.sh.in @@ -57,6 +57,14 @@ case ${mode} in done ;; +"format") + echo "Formatting the following Terraform modules:" + for module in "${terraformModules[@]}"; do + echo " ${module}" + ${terraform} -chdir="${module}" fmt -recursive > /dev/null + done + ;; + "generate") echo "Formatting and generating lock files for the following Terraform modules:" 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_amd64 > /dev/null ${terraform} -chdir="${module}" providers lock -platform=windows_amd64 > /dev/null - ${terraform} -chdir="${module}" fmt -recursive > /dev/null rm -rf "${module}/.terraform" done ;;