#!/usr/bin/env bash set -euo pipefail ACTION="${1:-}" if [[ -z "$ACTION" ]]; then echo "Usage: $0 " 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/ and live//. if [[ "$stack_dir" == "live" ]]; then continue fi echo "=== STACK: ${stack_dir} ===" ( cd "$stack_dir" terragrunt init -upgrade -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