-
Notifications
You must be signed in to change notification settings - Fork 2
68 lines (59 loc) · 2.48 KB
/
destroy.yaml
File metadata and controls
68 lines (59 loc) · 2.48 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
name: Terraform Destroy
on:
workflow_dispatch:
inputs:
environment:
description: "Environment name"
required: true
type: choice
options:
- dev
- prod
jobs:
destroy:
runs-on: ubuntu-latest
name: Destroys ${{ inputs.environment }} Environment
environment:
name: ${{ inputs.environment }}
url: https://${{ vars.DOMAIN_NAME }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.9.8
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ vars.region }}
- name: Set Environment Variables
run: |
echo "TF_VAR_environment=${{ inputs.environment }}-env" >> $GITHUB_ENV
echo "TF_VAR_project_id=${{ vars.project_id }}" >> $GITHUB_ENV
echo "TF_VAR_org_id=${{ vars.org_id }}" >> $GITHUB_ENV
CRED_PATH=$(pwd)/credentials.json
echo ${{ secrets.credentials }} >> $CRED_PATH
echo "CRED_PATH=$CRED_PATH" >> $GITHUB_ENV
echo "TF_VAR_credentials=$CRED_PATH" >> $GITHUB_ENV
echo "TF_VAR_billing_account=${{ secrets.billing_account }}" >> $GITHUB_ENV
echo "TF_VAR_repository_username=${{ secrets.repository_username }}" >> $GITHUB_ENV
echo "TF_VAR_repository_password=${{ secrets.repository_password }}" >> $GITHUB_ENV
echo "TF_VAR_db_username=${{ secrets.TF_VAR_db_username }}" >> $GITHUB_ENV
echo "TF_VAR_db_password=${{ secrets.TF_VAR_db_password }}" >> $GITHUB_ENV
- name: Terraform Init
run: |
terraform init -var-file=${{ inputs.environment }}.tfvars \
-backend-config="bucket=${{ secrets.backend_bucket_name }}" \
-backend-config="encryption_key=${{ secrets.backend_encryption_key }}" \
-backend-config="credentials=$CRED_PATH" \
-backend-config="prefix=terraform/state"
- name: Terraform Plan
run: |
terraform plan -destroy -var-file=${{ inputs.environment }}.tfvars -out=plan.tfplan
- name: Terraform Destroy
if: github.event_name == 'workflow_dispatch'
run: |
terraform destroy -auto-approve -var-file=${{ inputs.environment }}.tfvars