Skip to content

Commit

Permalink
bazel: separate paths to check
Browse files Browse the repository at this point in the history
  • Loading branch information
msanft committed Nov 22, 2023
1 parent 7267a0e commit b3a3c00
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions bazel/ci/terraform.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@ readarray -t <<< "$(
sort -ud
)"
terraformPaths=("${MAPFILE[@]}")
terraformModules=()
terraformFormatModules=()
terraformLockModules=()
terraformCheckModules=()
pathPrefix="${terraformPaths[0]}"
for ((i = 1; i < ${#terraformPaths[@]}; i++)); do
path="${terraformPaths[i]}"
if [[ ${path} == "${pathPrefix}"* ]]; then
continue
fi
terraformModules+=("${pathPrefix}")
terraformFormatModules+=("${pathPrefix}")
terraformLockModules+=("${pathPrefix}")
terraformCheckModules+=("${pathPrefix}")
pathPrefix="${path}"
done

Expand All @@ -46,13 +48,18 @@ excludeLockDirs=(
"terraform-provider-constellation"
)

excludeCheckDirs=(
"build"
"terraform-provider-constellation"
)

check() {
echo "The following Terraform modules are excluded and won't be tidied:"
echo "The following Terraform modules are excluded and won't be formatted:"
for exclude in "${excludeDirs[@]}"; do
for i in "${!terraformModules[@]}"; do
if [[ ${terraformModules[i]} == "${BUILD_WORKSPACE_DIRECTORY}/${exclude}"* ]]; then
echo " ${terraformModules[i]}"
unset 'terraformModules[i]'
for i in "${!terraformFormatModules[@]}"; do
if [[ ${terraformFormatModules[i]} == "${BUILD_WORKSPACE_DIRECTORY}/${exclude}"* ]]; then
echo " ${terraformFormatModules[i]}"
unset 'terraformFormatModules[i]'
fi
done
done
Expand All @@ -67,14 +74,24 @@ check() {
done
done

echo "The following Terraform modules are excluded and won't be checked:"
for exclude in "${excludeCheckDirs[@]}"; do
for i in "${!terraformCheckModules[@]}"; do
if [[ ${terraformCheckModules[i]} == "${BUILD_WORKSPACE_DIRECTORY}/${exclude}"* ]]; then
echo " ${terraformCheckModules[i]}"
unset 'terraformCheckModules[i]'
fi
done
done

case ${mode} in
"check")
echo "Checking validity and format of the following Terraform modules:"
for script in "${terraformModules[@]}"; do
for script in "${terraformCheckModules[@]}"; do
echo " ${script}"
done
echo "This may take a minute..."
for module in "${terraformModules[@]}"; do
for module in "${terraformCheckModules[@]}"; do
${terraform} -chdir="${module}" init > /dev/null
${terraform} -chdir="${module}" fmt -recursive > /dev/null
${terraform} -chdir="${module}" validate > /dev/null
Expand All @@ -84,7 +101,7 @@ check() {

"format")
echo "Formatting the following Terraform modules:"
for module in "${terraformModules[@]}"; do
for module in "${terraformFormatModules[@]}"; do
echo " ${module}"
${terraform} -chdir="${module}" fmt -recursive > /dev/null
done
Expand Down

0 comments on commit b3a3c00

Please sign in to comment.