-
Notifications
You must be signed in to change notification settings - Fork 0
69 lines (56 loc) · 1.79 KB
/
terraform_destroy.yml
File metadata and controls
69 lines (56 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
name: Terraform Destroy (Manually Triggered)
on:
workflow_dispatch:
inputs:
confirm:
description: "Type 'DESTROY' to confirm you really want to destroy infrastructure"
required: true
env:
TF_ROOT: project1_refactor
TF_VERSION: 1.13.0
AWS_REGION: eu-west-2
concurrency:
group: terraform-destroy-${{ github.ref }}
cancel-in-progress: false
jobs:
destroy:
runs-on: ubuntu-latest
permissions:
id-token: write # Required for OIDC
contents: read # To checkout repo
steps:
- name: ⛔ Validate destroy confirmation
if: ${{ github.event.inputs.confirm != 'DESTROY' }}
run: |
echo "❌ Destroy not confirmed. Type 'DESTROY' in the workflow input."
exit 1
- name: 📥 Checkout repo
uses: actions/checkout@v4
- name: 🔐 Configure AWS credentials (OIDC)
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_OIDC_ROLE }}
aws-region: ${{ env.AWS_REGION }}
- name: 🧪 Verify Remote State S3 Backend
run: |
aws s3api head-bucket \
--bucket my-eu-tf-state-bucket
- name: 🧪 Verify DynamoDB Lock Table
run: |
aws dynamodb describe-table \
--table-name terraform-locks
- name: 🛠️ Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TF_VERSION }}
- name: 📄 Terraform Init
run: |
terraform -chdir=${{ env.TF_ROOT }} \
init \
-input=false \
-backend-config="region=${{ env.AWS_REGION }}"
- name: 💣 Terraform Destroy
run: |
terraform -chdir=${{ env.TF_ROOT }} \
destroy \
-auto-approve