fix(ci): robust terraform destroy with lock cleanup and re-init

Terraform destroy now handles cancelled runs gracefully:
- Re-runs terraform init (in case it didn't complete)
- Force-unlocks stale state locks from killed apply steps
- Cleans up state files so next run starts fresh

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Clint Branham
2026-03-18 14:33:32 -05:00
parent cda603d920
commit 0514dffc3e
+10 -1
View File
@@ -221,4 +221,13 @@ jobs:
TF_VAR_target_node: ${{ secrets.PVE_TARGET_NODE }}
TF_VAR_iso_local_path: /tmp/${{ steps.iso.outputs.filename }}
TF_VAR_test_vm_password: ${{ env.PVE_PASSWORD }}
run: terraform destroy -auto-approve -input=false
run: |
terraform init -input=false
# Clear stale lock from cancelled runs
if [ -f .terraform.tfstate.lock.info ]; then
LOCK_ID=$(python3 -c "import json; print(json.load(open('.terraform.tfstate.lock.info'))['ID'])")
terraform force-unlock -force "$LOCK_ID" || true
fi
terraform destroy -auto-approve -input=false || true
# Clean up state so next run starts fresh
rm -f terraform.tfstate terraform.tfstate.backup .terraform.tfstate.lock.info