fix: harden destroy workflow and recover state push
All checks were successful
Terraform Plan / Terraform Plan (push) Successful in 13s
All checks were successful
Terraform Plan / Terraform Plan (push) Successful in 13s
This commit is contained in:
@@ -36,7 +36,7 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: https://gitea.com/actions/checkout@v4
|
||||||
|
|
||||||
- name: Create Terraform secret files
|
- name: Create Terraform secret files
|
||||||
working-directory: terraform
|
working-directory: terraform
|
||||||
@@ -65,6 +65,7 @@ jobs:
|
|||||||
uses: hashicorp/setup-terraform@v2
|
uses: hashicorp/setup-terraform@v2
|
||||||
with:
|
with:
|
||||||
terraform_version: 1.6.6
|
terraform_version: 1.6.6
|
||||||
|
terraform_wrapper: false
|
||||||
|
|
||||||
- name: Terraform Init
|
- name: Terraform Init
|
||||||
working-directory: terraform
|
working-directory: terraform
|
||||||
@@ -91,4 +92,20 @@ jobs:
|
|||||||
|
|
||||||
- name: Terraform Destroy Apply
|
- name: Terraform Destroy Apply
|
||||||
working-directory: terraform
|
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"
|
||||||
|
|||||||
Reference in New Issue
Block a user