-
Notifications
You must be signed in to change notification settings - Fork 2
118 lines (102 loc) · 3.45 KB
/
tear-down-sandbox.yml
File metadata and controls
118 lines (102 loc) · 3.45 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
name: "Tear down - Sandbox/Test"
run-name: "${{ github.event.inputs.git_ref }} | ${{ github.event.inputs.sandbox_name }} | ${{ github.event.inputs.environment }}"
on:
workflow_dispatch:
inputs:
git_ref:
default: "main"
description: "Branch, tag or SHA for the destroy action"
required: true
type: "string"
sandbox_name:
description: "Sandbox to destroy"
required: true
type: "string"
environment:
default: "development"
description: "GitHub Environment name"
required: true
type: choice
options:
- "development"
- "test"
workflow_call:
inputs:
git_ref:
default: "main"
description: "Branch, tag or SHA for the destroy action"
required: true
type: "string"
sandbox_name:
description: "Sandbox to destroy"
required: true
type: "string"
environment:
default: "development"
description: "GitHub Environment name"
required: true
type: "string"
permissions:
pull-requests: write
id-token: write
contents: read
jobs:
remove_edge_associations:
name: Remove Lambda@Edge Associations
uses: ./.github/workflows/base-cleanup-lambda-edge.yml
with:
git_ref: ${{ inputs.git_ref }}
sandbox_name: ${{ inputs.sandbox_name }}
environment: ${{ inputs.environment }}
secrets:
AWS_ASSUME_ROLE: ${{ secrets.AWS_ASSUME_ROLE }}
cleanup_versions:
name: Cleanup Versions
uses: ./.github/workflows/base-cleanup-workspace.yml
with:
git_ref: ${{ inputs.git_ref }}
sandbox_name: ${{ inputs.sandbox_name }}
environment: ${{ inputs.environment }}
secrets:
AWS_ASSUME_ROLE: ${{ secrets.AWS_ASSUME_ROLE }}
terraform_destroy:
name: Terraform Destroy
runs-on: ubuntu-latest
needs: [remove_edge_associations] # Ensure this runs after Lambda@Edge removal
environment: ${{ inputs.environment }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
ref: ${{ inputs.git_ref }}
- name: Setup Python 3.11
uses: actions/setup-python@v6
with:
python-version: 3.11
- name: Install Python Dependencies
run: |
python3 -m venv ./venv
./venv/bin/pip3 install --upgrade pip boto3
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v5
with:
role-to-assume: ${{ secrets.AWS_ASSUME_ROLE }}
aws-region: ${{ vars.AWS_REGION }}
mask-aws-account-id: true
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.14.3
- name: Initialise Terraform
run: terraform init -backend-config=${{ vars.TF_BACKEND_FILE }}
working-directory: ./infrastructure
- name: Select Terraform Workspace
run: terraform workspace select ${{ inputs.sandbox_name }}
working-directory: ./infrastructure
- name: Run Terraform Destroy
run: terraform destroy -auto-approve -var-file="${{ vars.TF_VARS_FILE }}"
working-directory: ./infrastructure
- name: Run Cleanup Script (Terraform Workspace)
run: ./venv/bin/python3 -u scripts/cleanup_terraform_states.py ${{ inputs.sandbox_name }}
- name: Run Cleanup Script (Log Group)
run: ./venv/bin/python3 -u scripts/cleanup_log_groups.py ${{ inputs.sandbox_name }}