Skip to content

Commit ca7e453

Browse files
committed
Included pruning for ghost ressources
1 parent d95ed62 commit ca7e453

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

.github/workflows/deploy-azure.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff 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 }

0 commit comments

Comments
 (0)