File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed
Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -110,6 +110,19 @@ jobs:
110110
111111 echo "::endgroup::"
112112
113+ # ── just AFTER the import block ─────────────────────────────────
114+ - name : Prune stale resources from state
115+ env : { TF_IN_AUTOMATION: true }
116+ run : |
117+ set -euo pipefail
118+ for ADDR in $(terraform -chdir="$TF_DIR" state list); do
119+ ID=$(terraform -chdir="$TF_DIR" state show -no-color "$ADDR" | awk '/^id +=/ {print $3}')
120+ if ! az resource show --ids "$ID" --query "id" -o tsv &>/dev/null; then
121+ echo "⚠️ Azure resource missing → $ADDR ($ID) — removing from state"
122+ terraform -chdir="$TF_DIR" state rm "$ADDR"
123+ fi
124+ done
125+
113126 # ────────────────────── Terraform apply ────────────────────
114127 - name : Terraform apply
115128 env : { TF_IN_AUTOMATION: true }
You can’t perform that action at this time.
0 commit comments