forked from ine-labs/AWSGoat
-
Notifications
You must be signed in to change notification settings - Fork 0
56 lines (47 loc) · 1.47 KB
/
tf-destroy-main.yml
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
name: 'Terraform Destroy'
on:
workflow_dispatch:
inputs:
module:
type: choice
description: "Select which module to destroy"
options:
- module-1
- module-2
required: true
permissions: write-all
jobs:
terraform:
name: 'Terraform'
runs-on: ubuntu-latest
environment: production
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: "us-east-1"
defaults:
run:
shell: bash
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v3
- name: Set Account ID
id: account
run: |
echo "::set-output name=ACCOUNT_ID::$(aws sts get-caller-identity --query Account --output text)"
# Copy and delete terraform.tfstate files from s3 bucket
- name: Retrieve tfstate
run: |
cd modules/${{ github.event.inputs.module }}
aws s3 cp s3://do-not-delete-awsgoat-state-files-${{ steps.account.outputs.ACCOUNT_ID }}/terraform.tfstate ./terraform.tfstate
# Initialize a new Terraform working directory
- name: Terraform Init
run: |
cd modules/${{ github.event.inputs.module }}
terraform init
- name: Terraform Destroy
run: |
cd modules/${{ github.event.inputs.module }}
terraform destroy -auto-approve -input=false
continue-on-error: false