From 0514dffc3edf536b14fd0b999226a73fd1aa118c Mon Sep 17 00:00:00 2001 From: Clint Branham Date: Wed, 18 Mar 2026 14:33:32 -0500 Subject: [PATCH] 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) --- .github/workflows/integration-tests.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 114839c..0549b27 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -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