Skip to content

Commit 276186a

Browse files
authored
Create aws-destroy.yml
1 parent c1e8b7f commit 276186a

File tree

1 file changed

+308
-0
lines changed

1 file changed

+308
-0
lines changed

.github/workflows/aws-destroy.yml

Lines changed: 308 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,308 @@
1+
name: "F5XC + NAP Destroy"
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
11+
terraform_arcadia:
12+
name: "Arcadia WebApp"
13+
runs-on: ubuntu-latest
14+
needs: terraform_xc
15+
defaults:
16+
run:
17+
working-directory: ./arcadia
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v3
21+
22+
- name: Setup Terraform
23+
uses: hashicorp/setup-terraform@v2
24+
with:
25+
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
26+
27+
- name: Setup Terraform Backend
28+
id: backend
29+
run: |
30+
cat > backend.tf << EOF
31+
terraform {
32+
cloud {
33+
organization = "${{ secrets.TF_CLOUD_ORGANIZATION }}"
34+
workspaces {
35+
name = "${{ secrets.TF_CLOUD_WORKSPACE_ARCADIA }}"
36+
}
37+
}
38+
}
39+
EOF
40+
- name: Terraform Init
41+
id: init
42+
run: terraform init
43+
44+
- name: Terraform Validate
45+
id: validate
46+
run: terraform validate -no-color
47+
48+
- name: Terraform Plan
49+
id: plan
50+
if: github.event_name == 'pull_request'
51+
run: terraform plan -no-color -input=false
52+
continue-on-error: true
53+
54+
- uses: actions/github-script@v6
55+
if: github.event_name == 'pull_request'
56+
env:
57+
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
58+
with:
59+
github-token: ${{ secrets.GITHUB_TOKEN }}
60+
script: |
61+
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
62+
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
63+
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
64+
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
65+
<details><summary>Show Plan</summary>
66+
\`\`\`\n
67+
${process.env.PLAN}
68+
\`\`\`
69+
</details>
70+
*Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
71+
github.rest.issues.createComment({
72+
issue_number: context.issue.number,
73+
owner: context.repo.owner,
74+
repo: context.repo.repo,
75+
body: output
76+
})
77+
- name: Terraform Plan Status
78+
if: steps.plan.outcome == 'failure'
79+
run: exit 1
80+
81+
- name: Terraform Destroy
82+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
83+
run: terraform destroy -auto-approve -input=false
84+
85+
terraform_nap:
86+
name: "NGINX App Protect"
87+
runs-on: ubuntu-latest
88+
needs: terraform_arcadia
89+
defaults:
90+
run:
91+
working-directory: ./nap
92+
steps:
93+
- name: Checkout
94+
uses: actions/checkout@v3
95+
96+
- name: Setup Terraform
97+
uses: hashicorp/setup-terraform@v2
98+
with:
99+
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
100+
101+
- name: Setup Terraform Backend
102+
id: backend
103+
run: |
104+
cat > backend.tf << EOF
105+
terraform {
106+
cloud {
107+
organization = "${{ secrets.TF_CLOUD_ORGANIZATION }}"
108+
workspaces {
109+
name = "${{ secrets.TF_CLOUD_WORKSPACE_NAP }}"
110+
}
111+
}
112+
}
113+
EOF
114+
echo ${{secrets.NGINX_JWT}} | base64 -d > nginx-repo.jwt
115+
- name: Terraform Init
116+
id: init
117+
run: terraform init
118+
119+
- name: Terraform Validate
120+
id: validate
121+
run: terraform validate -no-color
122+
123+
- name: Terraform Plan
124+
id: plan
125+
if: github.event_name == 'pull_request'
126+
run: terraform plan -no-color -input=false
127+
continue-on-error: true
128+
129+
- uses: actions/github-script@v6
130+
if: github.event_name == 'pull_request'
131+
env:
132+
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
133+
with:
134+
github-token: ${{ secrets.GITHUB_TOKEN }}
135+
script: |
136+
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
137+
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
138+
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
139+
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
140+
<details><summary>Show Plan</summary>
141+
\`\`\`\n
142+
${process.env.PLAN}
143+
\`\`\`
144+
</details>
145+
*Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
146+
github.rest.issues.createComment({
147+
issue_number: context.issue.number,
148+
owner: context.repo.owner,
149+
repo: context.repo.repo,
150+
body: output
151+
})
152+
- name: Terraform Plan Status
153+
if: steps.plan.outcome == 'failure'
154+
run: exit 1
155+
156+
- name: Terraform Destroy
157+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
158+
run: terraform destroy -auto-approve -input=false
159+
160+
terraform_eks:
161+
name: "AWS EKS"
162+
runs-on: ubuntu-latest
163+
needs: terraform_nap
164+
defaults:
165+
run:
166+
working-directory: ./eks-cluster
167+
steps:
168+
- name: Checkout
169+
uses: actions/checkout@v3
170+
171+
- name: Setup Terraform
172+
uses: hashicorp/setup-terraform@v2
173+
with:
174+
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
175+
176+
- name: Setup Terraform Backend
177+
id: backend
178+
run: |
179+
cat > backend.tf << EOF
180+
terraform {
181+
cloud {
182+
organization = "${{ secrets.TF_CLOUD_ORGANIZATION }}"
183+
workspaces {
184+
name = "${{ secrets.TF_CLOUD_WORKSPACE_EKS }}"
185+
}
186+
}
187+
}
188+
EOF
189+
190+
- name: Terraform Init
191+
id: init
192+
run: terraform init
193+
194+
- name: Terraform Validate
195+
id: validate
196+
run: terraform validate -no-color
197+
198+
- name: Terraform Plan
199+
id: plan
200+
if: github.event_name == 'pull_request'
201+
run: terraform plan -no-color -input=false
202+
continue-on-error: true
203+
204+
- uses: actions/github-script@v6
205+
if: github.event_name == 'pull_request'
206+
env:
207+
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
208+
with:
209+
github-token: ${{ secrets.GITHUB_TOKEN }}
210+
script: |
211+
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
212+
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
213+
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
214+
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
215+
<details><summary>Show Plan</summary>
216+
\`\`\`\n
217+
${process.env.PLAN}
218+
\`\`\`
219+
</details>
220+
*Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
221+
github.rest.issues.createComment({
222+
issue_number: context.issue.number,
223+
owner: context.repo.owner,
224+
repo: context.repo.repo,
225+
body: output
226+
})
227+
- name: Terraform Plan Status
228+
if: steps.plan.outcome == 'failure'
229+
run: exit 1
230+
231+
- name: Terraform Destroy
232+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
233+
run: terraform destroy -auto-approve -input=false
234+
235+
terraform_infra:
236+
name: "AWS Infra"
237+
runs-on: ubuntu-latest
238+
needs: terraform_eks
239+
defaults:
240+
run:
241+
working-directory: ./infra
242+
steps:
243+
- name: Checkout
244+
uses: actions/checkout@v3
245+
246+
- name: Setup Terraform
247+
uses: hashicorp/setup-terraform@v2
248+
with:
249+
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
250+
251+
- name: Setup Terraform Backend
252+
id: backend
253+
run: |
254+
cat > backend.tf << EOF
255+
terraform {
256+
cloud {
257+
organization = "${{ secrets.TF_CLOUD_ORGANIZATION }}"
258+
workspaces {
259+
name = "${{ secrets.TF_CLOUD_WORKSPACE_INFRA }}"
260+
}
261+
}
262+
}
263+
EOF
264+
265+
- name: Terraform Init
266+
id: init
267+
run: terraform init
268+
269+
- name: Terraform Validate
270+
id: validate
271+
run: terraform validate -no-color
272+
273+
- name: Terraform Plan
274+
id: plan
275+
if: github.event_name == 'pull_request'
276+
run: terraform plan -no-color -input=false
277+
continue-on-error: true
278+
279+
- uses: actions/github-script@v6
280+
if: github.event_name == 'pull_request'
281+
env:
282+
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
283+
with:
284+
github-token: ${{ secrets.GITHUB_TOKEN }}
285+
script: |
286+
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
287+
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
288+
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
289+
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
290+
<details><summary>Show Plan</summary>
291+
\`\`\`\n
292+
${process.env.PLAN}
293+
\`\`\`
294+
</details>
295+
*Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
296+
github.rest.issues.createComment({
297+
issue_number: context.issue.number,
298+
owner: context.repo.owner,
299+
repo: context.repo.repo,
300+
body: output
301+
})
302+
- name: Terraform Plan Status
303+
if: steps.plan.outcome == 'failure'
304+
run: exit 1
305+
306+
- name: Terraform Destroy
307+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
308+
run: terraform destroy -auto-approve -input=false

0 commit comments

Comments
 (0)