terraform-contour-mirror/scripts/run_all_stacks.sh

46 lines
1.0 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
ACTION="${1:-}"
if [[ -z "$ACTION" ]]; then
echo "Usage: $0 <validate|plan|apply>"
exit 1
fi
STACK_FILES=()
while IFS= read -r tg; do
STACK_FILES+=("$tg")
done < <(find live -name 'terragrunt.hcl' -not -path '*/.terragrunt-cache/*' | sort)
if [[ ${#STACK_FILES[@]} -eq 0 ]]; then
echo "No terragrunt stacks found under live/"
exit 0
fi
for tg in "${STACK_FILES[@]}"; do
stack_dir="$(dirname "$tg")"
# Skip only root-level Terragrunt configuration file (live/terragrunt.hcl).
# Execute concrete stacks like live/<component> and live/<group>/<component>.
if [[ "$stack_dir" == "live" ]]; then
continue
fi
echo "=== STACK: ${stack_dir} ==="
(
cd "$stack_dir"
terragrunt init -reconfigure
if [[ "$ACTION" == "validate" ]]; then
terragrunt validate
elif [[ "$ACTION" == "plan" ]]; then
terragrunt plan -out=tfplan
elif [[ "$ACTION" == "apply" ]]; then
terragrunt apply -auto-approve
else
echo "Unknown action: $ACTION"
exit 1
fi
)
done