fix: harden destroy workflow and recover state push
All checks were successful
Terraform Plan / Terraform Plan (push) Successful in 13s

This commit is contained in:
2026-02-28 15:17:42 +00:00
parent df4740071a
commit 1304afd793

View File

@@ -36,7 +36,7 @@ jobs:
fi
- name: Checkout repository
uses: actions/checkout@v4
uses: https://gitea.com/actions/checkout@v4
- name: Create Terraform secret files
working-directory: terraform
@@ -65,6 +65,7 @@ jobs:
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.6.6
terraform_wrapper: false
- name: Terraform Init
working-directory: terraform
@@ -91,4 +92,20 @@ jobs:
- name: Terraform Destroy Apply
working-directory: terraform
run: terraform apply -auto-approve tfdestroy
run: |
set +e
terraform apply -auto-approve tfdestroy 2>&1 | tee destroy-apply.log
APPLY_EXIT=${PIPESTATUS[0]}
if [ "$APPLY_EXIT" -ne 0 ] && [ -f errored.tfstate ] && grep -q "Failed to persist state to backend" destroy-apply.log; then
echo "Detected backend state write failure after destroy; attempting recovery push..."
terraform state push errored.tfstate
PUSH_EXIT=$?
if [ "$PUSH_EXIT" -eq 0 ]; then
echo "Recovered by pushing errored.tfstate to backend."
exit 0
fi
fi
exit "$APPLY_EXIT"