-
Notifications
You must be signed in to change notification settings - Fork 0
59 lines (50 loc) · 1.64 KB
/
destroy.yaml
File metadata and controls
59 lines (50 loc) · 1.64 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
name: Terraform Destroy
on:
workflow_dispatch:
inputs:
environment:
description: "Environment to destroy"
required: true
type: choice
options:
- staging
- prod
env:
TF_WORKING_DIR: terraform
jobs:
destroy:
name: Terraform Destroy
runs-on: ubuntu-latest
environment: ${{ github.event.inputs.environment }}
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.5.6
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
# Backend selection based on input
- name: Terraform Init
working-directory: ${{ env.TF_WORKING_DIR }}
run: |
if [ "${{ github.event.inputs.environment }}" = "staging" ]; then
terraform init -reconfigure -backend-config=backend-staging.tfvars -input=false
else
terraform init -reconfigure -backend-config=backend-prod.tfvars -input=false
fi
- name: Terraform Destroy
working-directory: ${{ env.TF_WORKING_DIR }}
run: |
if [ "${{ github.event.inputs.environment }}" = "staging" ]; then
terraform destroy -var-file="staging.tfvars" -auto-approve
else
terraform destroy -var-file="prod.tfvars" -auto-approve
fi