|
| 1 | +# Find all directories containing .terraform.lock.hcl files |
| 2 | +workspaces := `find . -name ".terraform.lock.hcl" -exec dirname {} \; | tr '\n' ' '` |
| 3 | + |
| 4 | +# Show available recipes |
| 5 | +default: |
| 6 | + @just --list |
| 7 | + |
| 8 | +# Format Terraform files in all workspaces |
| 9 | +format: |
| 10 | + @echo "Formatting Terraform files in all workspaces..." |
| 11 | + @for workspace in {{workspaces}}; do \ |
| 12 | + echo "Formatting $workspace"; \ |
| 13 | + terraform -chdir=$workspace fmt; \ |
| 14 | + done |
| 15 | + @echo "Formatting complete." |
| 16 | + |
| 17 | +# List all detected Terraform workspaces |
| 18 | +list-workspaces: |
| 19 | + @echo "Detected Terraform workspaces:" |
| 20 | + @for workspace in {{workspaces}}; do \ |
| 21 | + echo " $workspace"; \ |
| 22 | + done |
| 23 | + |
| 24 | +# Validate Terraform configurations in all workspaces |
| 25 | +validate: |
| 26 | + @echo "Validating Terraform configurations in all workspaces..." |
| 27 | + @for workspace in {{workspaces}}; do \ |
| 28 | + echo "Validating $workspace"; \ |
| 29 | + terraform -chdir=$workspace validate; \ |
| 30 | + done |
| 31 | + @echo "Validation complete." |
| 32 | + |
| 33 | +# Initialize Terraform in all workspaces |
| 34 | +init: |
| 35 | + @echo "Initializing Terraform in all workspaces..." |
| 36 | + @for workspace in {{workspaces}}; do \ |
| 37 | + echo "Initializing $workspace"; \ |
| 38 | + terraform -chdir=$workspace init; \ |
| 39 | + done |
| 40 | + @echo "Initialization complete." |
| 41 | + |
| 42 | +# Initialize and upgrade Terraform in all workspaces |
| 43 | +init-upgrade: |
| 44 | + @echo "Initializing and upgrading Terraform in all workspaces..." |
| 45 | + @for workspace in {{workspaces}}; do \ |
| 46 | + echo "Initializing and upgrading $workspace"; \ |
| 47 | + terraform -chdir=$workspace init -upgrade; \ |
| 48 | + done |
| 49 | + @echo "Initialization and upgrade complete." |
| 50 | + |
| 51 | +# Run Terraform plan in all workspaces |
| 52 | +plan: |
| 53 | + @echo "Running Terraform plan in all workspaces..." |
| 54 | + @for workspace in {{workspaces}}; do \ |
| 55 | + echo "Planning $workspace"; \ |
| 56 | + terraform -chdir=$workspace plan; \ |
| 57 | + done |
| 58 | + @echo "Planning complete." |
| 59 | + |
| 60 | +# Remove Terraform cache files from all workspaces |
| 61 | +[confirm("This will delete .terraform, tfstate, and lock files. Continue?")] |
| 62 | +clean: |
| 63 | + @echo "Cleaning Terraform cache files from all workspaces..." |
| 64 | + @for workspace in {{workspaces}}; do \ |
| 65 | + echo "Cleaning $workspace"; \ |
| 66 | + rm -rf $workspace/.terraform $workspace/*.tfstate* $workspace/.terraform.lock.hcl; \ |
| 67 | + done |
| 68 | + @echo "Cleaning complete." |
0 commit comments