Skip to content

Commit a2cdcd1

Browse files
Added destroy workflow
1 parent 0e680f0 commit a2cdcd1

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

.github/workflows/destroy.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Terraform Destroy
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
environment:
7+
description: "Environment to destroy"
8+
required: true
9+
type: choice
10+
options:
11+
- staging
12+
- prod
13+
14+
env:
15+
TF_WORKING_DIR: terraform/
16+
17+
jobs:
18+
destroy:
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
25+
- name: Setup Terraform
26+
uses: hashicorp/setup-terraform@v2
27+
with:
28+
terraform_version: 1.5.6
29+
30+
- name: Configure AWS Credentials
31+
uses: aws-actions/configure-aws-credentials@v2
32+
with:
33+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
34+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
35+
aws-region: ${{ secrets.AWS_REGION }}
36+
37+
- name: Terraform Init
38+
working-directory: ${{ env.TF_WORKING_DIR }}
39+
run: terraform init -input=false
40+
41+
- name: Terraform Destroy
42+
working-directory: ${{ env.TF_WORKING_DIR }}
43+
run: |
44+
if [ "${{ github.event.inputs.environment }}" = "staging" ]; then
45+
terraform destroy -var-file="staging.tfvars" -auto-approve
46+
else
47+
terraform destroy -var-file="prod.tfvars" -auto-approve
48+
fi

0 commit comments

Comments
 (0)