-
Notifications
You must be signed in to change notification settings - Fork 0
142 lines (125 loc) · 4.24 KB
/
ci-iac.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
name: CI / IaC
on:
pull_request:
branches: [dev, stg, prd]
types: [opened, reopened, synchronize, edited]
paths:
- 'terraform-iac/**'
- '.github/workflows/ci-iac.yml'
env:
tf_version: "1.7.0" # must match value in terraform-iac/*/app/main.tf
jobs:
env:
name: Set Env Vars
timeout-minutes: 1
runs-on: ubuntu-latest
steps:
- name: Set up DEV Environment Variables
if: github.base_ref == 'dev'
run: |
matrix='{
"env":[
{
"environment_name":"dev",
"tf_working_dir":"./terraform-iac/dev/app",
"aws_account":"977306314792",
"aws_gha_role":"hw-fargate-api-dev-gha"
}
]
}'
echo matrix=`echo $matrix | jq -c .` >> $GITHUB_ENV
- name: Set up STG Environment Variables
if: github.base_ref == 'stg'
run: |
matrix='{
"env":[
{
"environment_name":"stg",
"tf_working_dir":"./terraform-iac/stg/app",
"aws_account":"977306314792",
"aws_gha_role":"hw-fargate-api-stg-gha"
}
]
}'
echo matrix=`echo $matrix | jq -c .` >> $GITHUB_ENV
- name: Set up PRD/CPY Environment Variables
if: github.base_ref == 'prd'
run: |
matrix='{
"env":[
{
"environment_name":"prd",
"tf_working_dir":"./terraform-iac/prd/app",
"aws_account":"539738229445",
"aws_gha_role":"hw-fargate-api-prd-gha"
},
{
"environment_name":"cpy",
"tf_working_dir":"./terraform-iac/cpy/app",
"aws_account":"539738229445",
"aws_gha_role":"hw-fargate-api-cpy-gha"
}
]
}'
echo matrix=`echo $matrix | jq -c .` >> $GITHUB_ENV
outputs:
matrix: ${{ env.matrix }}
format:
name: Terraform Format
timeout-minutes: 3
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Terraform Setup
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.tf_version }}
- name: Terraform Format
working-directory: terraform-iac
run: terraform fmt -check -recursive
plan:
name: Terraform Plan / ${{ matrix.env.environment_name }}
timeout-minutes: 6
runs-on: ubuntu-latest
needs: env
strategy:
matrix: ${{ fromJson(needs.env.outputs.matrix) }}
fail-fast: false
permissions:
contents: read
actions: read
pull-requests: write
id-token: write
steps:
- uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: "arn:aws:iam::${{ matrix.env.aws_account }}:role/${{ matrix.env.aws_gha_role }}"
role-session-name: ${{ github.sha }}
aws-region: us-west-2
- name: Terraform Setup
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.tf_version }}
- name: Terraform Init
working-directory: ${{ matrix.env.tf_working_dir }}
run: terraform init
- name: Terraform Plan
working-directory: ${{ matrix.env.tf_working_dir }}
run: terraform plan -var 'image_tag=ci_test' -input=false -out plan -lock=false
- name: Comment Terraform Plan
uses: byu-oit/github-action-tf-plan-comment@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
working-directory: ${{ matrix.env.tf_working_dir }}
terraform-plan-file: plan
- name: Analyze Terraform Plan
uses: byu-oit/github-action-tf-plan-analyzer@staging
if: github.repository_owner == 'byu-oit'
# If you're at BYU, but outside the byu-oit GitHub org, you may be able to obtain credentials by contacting [email protected]
with:
working-directory: ${{ matrix.env.tf_working_dir }}
terraform-plan-file: plan
divvycloud-username: ${{ secrets.DIVVYCLOUD_USERNAME }}
divvycloud-password: ${{ secrets.DIVVYCLOUD_PASSWORD }}