-
Notifications
You must be signed in to change notification settings - Fork 1
354 lines (326 loc) · 14.8 KB
/
infrastructure.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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
---
name: "infrastructure"
on: # yamllint disable-line rule:truthy
workflow_dispatch:
push:
paths:
- "**.tf"
- "cloud-init/*"
branches:
- "main"
permissions:
id-token: write
contents: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
jobs:
terraform:
name: Terraform Init
runs-on: ubuntu-latest
outputs:
action: ${{ steps.terraform.outputs.action }}
steps:
- id: terraform
name: ${{ github.ref_name }}
shell: bash
run: |
env
if [[ -n "${{ vars.DEPLOYED }}" ]]
then
if [[ "${{ vars.DEPLOYED }}" == "true" ]]
then
echo 'action=apply' >> "${GITHUB_OUTPUT}"
else
echo 'action=destroy' >> "${GITHUB_OUTPUT}"
fi
else
echo 'action=skip' >> "${GITHUB_OUTPUT}"
fi
plan:
needs: [terraform]
if: needs.terraform.outputs.action == 'apply'
name: Terraform Plan
runs-on: ubuntu-latest
env:
ARM_SKIP_PROVIDER_REGISTRATION: true
outputs:
tfplanExitCode: ${{ steps.tf-plan.outputs.exitcode }}
steps:
- name: Github repository checkout
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871
- name: Microsoft Azure Authentication
uses: azure/login@a65d910e8af852a8061c627c456678983e180302
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Hashicorp Terraform
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd
with:
terraform_wrapper: false
- name: terraform init
id: init
env:
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }}
TF_IN_AUTOMATION: true
TF_CLI_ARGS_init: -backend-config="storage_account_name=${{ secrets.AZURE_STORAGE_ACCOUNT_NAME }}" -backend-config="container_name=${{ secrets.TFSTATE_CONTAINER_NAME }}" -backend-config="resource_group_name=${{ secrets.AZURE_TFSTATE_RESOURCE_GROUP_NAME }}" -backend-config="key=${{ github.ref_name }}" -input=false
run: terraform init
- name: terraform plan
id: tf-plan
env:
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }}
TF_VAR_ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
TF_VAR_PROJECT_NAME: ${{ vars.PROJECT_NAME }}
TF_VAR_LOCATION: ${{ vars.LOCATION }}
TF_VAR_GITHUB_TOKEN: ${{ secrets.PAT }}
TF_VAR_GITHUB_ORG: ${{ vars.ORG }}
TF_VAR_DOCS_BUILDER_REPO_NAME: ${{ vars.DOCS_BUILDER_REPO_NAME }}
TF_VAR_MANIFESTS_INFRASTRUCTURE_SSH_PRIVATE_KEY: ${{ secrets.MANIFESTS_INFRASTRUCTURE_SSH_PRIVATE_KEY }}
TF_VAR_MANIFESTS_INFRASTRUCTURE_REPO_NAME: ${{ vars.MANIFESTS_INFRASTRUCTURE_REPO_NAME }}
TF_VAR_MANIFESTS_APPLICATIONS_SSH_PRIVATE_KEY: ${{ secrets.MANIFESTS_APPLICATIONS_SSH_PRIVATE_KEY }}
TF_VAR_MANIFESTS_APPLICATIONS_REPO_NAME: ${{ vars.MANIFESTS_APPLICATIONS_REPO_NAME }}
TF_VAR_HUB_NVA_PASSWORD: ${{ secrets.HUB_NVA_PASSWORD }}
TF_VAR_HUB_NVA_USERNAME: ${{ secrets.HUB_NVA_USERNAME }}
TF_VAR_LW_AGENT_TOKEN: ${{ secrets.LW_AGENT_TOKEN }}
TF_VAR_PRODUCTION_ENVIRONMENT: ${{ vars.PRODUCTION_ENVIRONMENT }}
TF_VAR_GPU_NODE_POOL: ${{ vars.GPU_NODE_POOL }}
TF_VAR_APPLICATION_DOCS: ${{ vars.APPLICATION_DOCS }}
TF_VAR_APPLICATION_SIGNUP: ${{ vars.APPLICATION_SIGNUP }}
TF_VAR_APPLICATION_OLLAMA: ${{ vars.APPLICATION_OLLAMA }}
TF_VAR_APPLICATION_DVWA: ${{ vars.APPLICATION_DVWA }}
TF_VAR_APPLICATION_VIDEO: ${{ vars.APPLICATION_VIDEO }}
TF_VAR_MANAGEMENT_PUBLIC_IP: ${{ vars.MANAGEMENT_PUBLIC_IP }}
TF_VAR_HTUSERNAME: ${{ secrets.HTUSERNAME }}
TF_VAR_HTPASSWD: ${{ secrets.HTPASSWD }}
TF_VAR_DNS_ZONE: ${{ vars.DNS_ZONE }}
TF_VAR_OWNER_EMAIL: ${{ secrets.OWNER_EMAIL }}
TF_VAR_NAME: ${{ vars.NAME }}
TF_VAR_LETSENCRYPT_URL: ${{ vars.LETSENCRYPT_URL }}
TF_IN_AUTOMATION: true
run: |
export exitcode=0
terraform plan -detailed-exitcode -no-color -out tfplan || export exitcode=$?
echo "exitcode=$exitcode" >> "$GITHUB_OUTPUT"
if [ $exitcode -eq 1 ]; then
echo Terraform Plan Failed!
exit 1
else
exit 0
fi
- name: Publish Terraform Plan
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882
with:
name: tfplan
path: ./
- name: Create String Output
id: tf-plan-string
run: |
TERRAFORM_PLAN=$(terraform show -no-color tfplan)
delimiter="$(openssl rand -hex 8)"
{
echo "summary<<${delimiter}"
echo "## Terraform Plan Output"
echo "<details><summary>Click to expand</summary>"
echo ""
echo '```terraform'
echo "$TERRAFORM_PLAN"
echo '```'
echo "</details>"
echo "${delimiter}"
} >> "$GITHUB_OUTPUT"
- name: Publish Terraform Plan to Task Summary
env:
SUMMARY: ${{ steps.tf-plan-string.outputs.summary }}
run: |
echo "$SUMMARY" >> "$GITHUB_STEP_SUMMARY"
# - name: Push Terraform Output to PR
# if: github.ref != 'refs/heads/main'
# uses: actions/github-script@v6
# env:
# SUMMARY: "${{ steps.tf-plan-string.outputs.summary }}"
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
# script: |
# const body = `${process.env.SUMMARY}`;
# github.rest.issues.createComment({
# issue_number: context.issue.number,
# owner: context.repo.owner,
# repo: context.repo.repo,
# body: body
# })
apply:
name: Terraform Apply
if: needs.terraform.outputs.action == 'apply'
runs-on: ubuntu-latest
needs: [terraform, plan]
steps:
- name: Github repository checkout
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871
- name: Microsoft Azure Authentication
uses: azure/login@a65d910e8af852a8061c627c456678983e180302
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Hashicorp Terraform
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd
with:
terraform_wrapper: false
- name: terraform init
id: init
env:
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }}
TF_IN_AUTOMATION: true
TF_CLI_ARGS_init: -backend-config="storage_account_name=${{ secrets.AZURE_STORAGE_ACCOUNT_NAME }}" -backend-config="container_name=${{ secrets.TFSTATE_CONTAINER_NAME }}" -backend-config="resource_group_name=${{ secrets.AZURE_TFSTATE_RESOURCE_GROUP_NAME }}" -backend-config="key=${{ github.ref_name }}" -input=false
run: terraform init
- name: Download Terraform Plan
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16
with:
name: tfplan
path: ./
- name: Terraform Apply
id: apply
env:
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }}
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
TF_VAR_ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
TF_VAR_PROJECT_NAME: ${{ vars.PROJECT_NAME }}
TF_VAR_LOCATION: ${{ vars.LOCATION }}
TF_VAR_GITHUB_TOKEN: ${{ secrets.PAT }}
TF_VAR_GITHUB_ORG: ${{ vars.ORG }}
TF_VAR_DOCS_BUILDER_REPO_NAME: ${{ vars.DOCS_BUILDER_REPO_NAME }}
TF_VAR_MANIFESTS_INFRASTRUCTURE_REPO_NAME: ${{ vars.MANIFESTS_INFRASTRUCTURE_REPO_NAME }}
TF_VAR_MANIFESTS_INFRASTRUCTURE_SSH_PRIVATE_KEY: ${{ secrets.MANIFESTS_INFRASTRUCTURE_SSH_PRIVATE_KEY }}
TF_VAR_MANIFESTS_APPLICATIONS_SSH_PRIVATE_KEY: ${{ secrets.MANIFESTS_APPLICATIONS_SSH_PRIVATE_KEY }}
TF_VAR_MANIFESTS_APPLICATIONS_REPO_NAME: ${{ vars.MANIFESTS_APPLICATIONS_REPO_NAME }}
TF_VAR_HUB_NVA_PASSWORD: ${{ secrets.HUB_NVA_PASSWORD }}
TF_VAR_HUB_NVA_USERNAME: ${{ secrets.HUB_NVA_USERNAME }}
TF_VAR_LW_AGENT_TOKEN: ${{ secrets.LW_AGENT_TOKEN }}
TF_VAR_PRODUCTION_ENVIRONMENT: ${{ vars.PRODUCTION_ENVIRONMENT }}
TF_VAR_GPU_NODE_POOL: ${{ vars.GPU_NODE_POOL }}
TF_VAR_APPLICATION_DOCS: ${{ vars.APPLICATION_DOCS }}
TF_VAR_APPLICATION_SIGNUP: ${{ vars.APPLICATION_SIGNUP }}
TF_VAR_APPLICATION_OLLAMA: ${{ vars.APPLICATION_OLLAMA }}
TF_VAR_APPLICATION_DVWA: ${{ vars.APPLICATION_DVWA }}
TF_VAR_APPLICATION_VIDEO: ${{ vars.APPLICATION_VIDEO }}
TF_VAR_MANAGEMENT_PUBLIC_IP: ${{ vars.MANAGEMENT_PUBLIC_IP }}
TF_VAR_HTUSERNAME: ${{ secrets.HTUSERNAME }}
TF_VAR_HTPASSWD: ${{ secrets.HTPASSWD }}
TF_VAR_DNS_ZONE: ${{ vars.DNS_ZONE }}
TF_VAR_OWNER_EMAIL: ${{ secrets.OWNER_EMAIL }}
TF_VAR_NAME: ${{ vars.NAME }}
TF_VAR_LETSENCRYPT_URL: ${{ vars.LETSENCRYPT_URL }}
TF_IN_AUTOMATION: true
GH_TOKEN: ${{ secrets.PAT }}
run: terraform apply -auto-approve tfplan
- name: Create Terraform Show Output
id: tf-show-output
env:
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }}
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
run: |
TERRAFORM_SHOW=$(terraform show -no-color)
delimiter="$(openssl rand -hex 8)"
{
echo "summary<<${delimiter}"
echo "## Terraform State Output"
echo "<details><summary>Click to expand</summary>"
echo ""
echo '```terraform'
echo "$TERRAFORM_SHOW"
echo '```'
echo "</details>"
echo "${delimiter}"
} >> "$GITHUB_OUTPUT"
- name: Publish Terraform Apply Output to Task Summary
env:
SUMMARY: ${{ steps.tf-show-output.outputs.summary }}
run: |
echo "$SUMMARY" >> "$GITHUB_STEP_SUMMARY"
destroy:
name: Terraform Destroy
needs: [terraform]
if: needs.terraform.outputs.action == 'destroy'
runs-on: ubuntu-latest
steps:
- name: Github repository checkout
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871
- name: Microsoft Azure Authentication
uses: azure/login@a65d910e8af852a8061c627c456678983e180302
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Hashicorp Terraform
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd
with:
terraform_wrapper: false
- name: terraform init
id: init
env:
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }}
TF_IN_AUTOMATION: true
TF_CLI_ARGS_init: -backend-config="storage_account_name=${{ secrets.AZURE_STORAGE_ACCOUNT_NAME }}" -backend-config="container_name=${{ secrets.TFSTATE_CONTAINER_NAME }}" -backend-config="resource_group_name=${{ secrets.AZURE_TFSTATE_RESOURCE_GROUP_NAME }}" -backend-config="key=${{ github.ref_name }}" -input=false
run: terraform init
- name: terraform destroy
id: destroy
env:
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }}
TF_VAR_ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
TF_VAR_PROJECT_NAME: ${{ vars.PROJECT_NAME }}
TF_VAR_LOCATION: ${{ vars.LOCATION }}
TF_VAR_GITHUB_TOKEN: ${{ secrets.PAT }}
TF_VAR_GITHUB_ORG: ${{ vars.ORG }}
TF_VAR_DOCS_BUILDER_REPO_NAME: ${{ vars.DOCS_BUILDER_REPO_NAME }}
TF_VAR_MANIFESTS_INFRASTRUCTURE_REPO_NAME: ${{ vars.MANIFESTS_INFRASTRUCTURE_REPO_NAME }}
TF_VAR_MANIFESTS_INFRASTRUCTURE_SSH_PRIVATE_KEY: ${{ secrets.MANIFESTS_INFRASTRUCTURE_SSH_PRIVATE_KEY }}
TF_VAR_MANIFESTS_APPLICATIONS_SSH_PRIVATE_KEY: ${{ secrets.MANIFESTS_APPLICATIONS_SSH_PRIVATE_KEY }}
TF_VAR_MANIFESTS_APPLICATIONS_REPO_NAME: ${{ vars.MANIFESTS_APPLICATIONS_REPO_NAME }}
TF_VAR_HUB_NVA_PASSWORD: ${{ secrets.HUB_NVA_PASSWORD }}
TF_VAR_HUB_NVA_USERNAME: ${{ secrets.HUB_NVA_USERNAME }}
TF_VAR_LW_AGENT_TOKEN: ${{ secrets.LW_AGENT_TOKEN }}
TF_VAR_PRODUCTION_ENVIRONMENT: ${{ vars.PRODUCTION_ENVIRONMENT }}
TF_VAR_GPU_NODE_POOL: ${{ vars.GPU_NODE_POOL }}
TF_VAR_APPLICATION_DOCS: ${{ vars.APPLICATION_DOCS }}
TF_VAR_APPLICATION_SIGNUP: ${{ vars.APPLICATION_SIGNUP }}
TF_VAR_APPLICATION_OLLAMA: ${{ vars.APPLICATION_OLLAMA }}
TF_VAR_APPLICATION_DVWA: ${{ vars.APPLICATION_DVWA }}
TF_VAR_APPLICATION_VIDEO: ${{ vars.APPLICATION_VIDEO }}
TF_VAR_MANAGEMENT_PUBLIC_IP: ${{ vars.MANAGEMENT_PUBLIC_IP }}
TF_VAR_HTUSERNAME: ${{ secrets.HTUSERNAME }}
TF_VAR_HTPASSWD: ${{ secrets.HTPASSWD }}
TF_VAR_DNS_ZONE: ${{ vars.DNS_ZONE }}
TF_VAR_OWNER_EMAIL: ${{ secrets.OWNER_EMAIL }}
TF_VAR_NAME: ${{ vars.NAME }}
TF_VAR_LETSENCRYPT_URL: ${{ vars.LETSENCRYPT_URL }}
TF_IN_AUTOMATION: true
run: |
terraform destroy -auto-approve
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@ff45666b9427631e3450c54a1bcbee4d9ff4d7c0
with:
token: ${{ secrets.PAT }}
repository: ${{ github.repository_owner }}/${{ secrets.APPLICATIONS_MANIFESTS_REPO_NAME }}
event-type: update-manifest
client-payload: |-
{
"type": "applications",
"name": "docs",
"file": "Deployment.yaml",
"spec": ".spec.template.spec.containers[0].image",
"value": "nginxinc/nginx-unprivileged:latest"
}