-
Notifications
You must be signed in to change notification settings - Fork 0
52 lines (44 loc) · 1.65 KB
/
destroy.yml
File metadata and controls
52 lines (44 loc) · 1.65 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
name: 'Destroy NodeBoot Website'
on:
workflow_dispatch:
jobs:
destroy:
name: 'Destroy'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_wrapper: false
- name: Terraform Init and Get Outputs
id: terraform
run: |
cd terraform
terraform init
# Fetch the S3 bucket name as an output
echo "S3_BUCKET_NAME=$(terraform output -json s3_bucket_name | jq -r .)" >> $GITHUB_ENV
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: eu-central-1
- name: Delete S3 Bucket Content
run: |
aws s3api list-object-versions --bucket $S3_BUCKET_NAME --output json --query "Versions[].{Key:Key,VersionId:VersionId}" | \
jq -r '.[] | "aws s3api delete-object --bucket $S3_BUCKET_NAME --key \(.Key) --version-id \(.VersionId)"' | \
sh
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: eu-central-1
S3_BUCKET_NAME: ${{ env.S3_BUCKET_NAME }}
- name: Destroy Resources
id: destroy_resources
run: |
cd terraform
terraform destroy -auto-approve -input=false
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: eu-central-1