generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 5
107 lines (87 loc) · 3.36 KB
/
terraform-ci-deploy.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
name: Terraform CI Deploy
on:
pull_request:
branches:
- main
workflow_dispatch:
jobs:
paths-filter:
runs-on: ubuntu-latest
outputs:
operations: ${{ steps.filter.outputs.operations }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
operations:
- 'operations/**'
terraform-deploy:
name: PR Infrastructure Deploy
needs: paths-filter
uses: ./.github/workflows/terraform-deploy_reusable.yml
if: needs.paths-filter.outputs.operations == 'true'
with:
TERRAFORM_DIRECTORY: operations/environments/pr
TERRAFORM_INIT_PARAMETERS: -backend-config="key=pr_${{ github.event.number }}.tfstate"
TERRAFORM_APPLY_PARAMETERS: -var="pr_number=${{ github.event.number }}"
secrets:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
terraform-deploy-skip: # runs when the PR doesn't have any changes that require the PR deploy; this ensures we get the appropriate required PR checks
name: PR Infrastructure Deploy # this name must match the above `terraform-deploy` job's name
needs: paths-filter
uses: ./.github/workflows/terraform-deploy_reusable-skip.yml
if: needs.paths-filter.outputs.operations != 'true'
pr-deploy:
name: PR Application Deploy
needs:
- terraform-deploy
- paths-filter
uses: ./.github/workflows/deploy_reusable.yml
if: needs.paths-filter.outputs.operations == 'true'
with:
ENVIRONMENT: pr
REPO: trusted-intermediary-router
REPO_DOCS: trusted-intermediary-docs
APP: ${{ needs.terraform-deploy.outputs.APP }}
REGISTRY: ${{ needs.terraform-deploy.outputs.REGISTRY }}
secrets:
ACR_USERNAME: ${{ needs.terraform-deploy.outputs.ACR_USERNAME }}
ACR_PASSWORD: ${{ needs.terraform-deploy.outputs.ACR_PASSWORD }}
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
pr-deploy-skip: # runs when the PR doesn't have any changes that require the PR deploy; this ensures we get the appropriate required PR checks
name: PR Application Deploy # this name must match the above `pr-deploy` job's name
needs:
- paths-filter
uses: ./.github/workflows/deploy_reusable-skip.yml
if: needs.paths-filter.outputs.operations != 'true'
destroy-environment:
name: Destroy PR Environment
needs:
- pr-deploy
- paths-filter
if: needs.paths-filter.outputs.operations == 'true' && always()
runs-on: ubuntu-latest
env:
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
ARM_USE_OIDC: true
permissions:
id-token: write
contents: read
defaults:
run:
working-directory: operations/environments/pr
steps:
- uses: actions/checkout@v4
- name: Terraform Init
id: init
run: terraform init -backend-config="key=pr_${{ github.event.number }}.tfstate"
- name: Terraform Destroy
run: terraform destroy -auto-approve -input=false -var="pr_number=${{ github.event.number }}"