-
Notifications
You must be signed in to change notification settings - Fork 2
294 lines (275 loc) · 9.59 KB
/
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
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
name: 'Terragrunt GitHub Actions'
on:
workflow_call:
inputs:
ENVIRONMENT:
required: true
type: string
WORKING_DIR:
required: true
type: string
TG_VERSION:
required: false
type: string
default: '0.58.2'
TF_VERSION:
required: false
type: string
default: '1.8.7'
AWS_REGION:
required: true
type: string
default: "us-east-2"
APPROVERS:
required: false
type: string
GCP_ENV:
required: false
type: boolean
default: true
TELEPORT_PROXY_URL:
required: false
type: string
default: ''
description: Default Teleport URL
TELEPORT_APP:
required: false
type: string
default: ''
description: An app registered on teleport to authenticate using proxy
GCP_WIP:
required: false
type: string
default: ''
description: GCP Workload Identity Provider
PROJECT_ID:
required: false
type: string
default: ''
description: GCP Project ID
GCP_SA:
required: false
type: string
default: ''
description: GCP Service Account
RUNNER:
required: true
type: string
default: ubuntu-latest
AZURE_ENV:
required: false
description: If Azure is required
type: boolean
default: false
secrets:
AWS_ACCESS_KEY_ID:
required: true
AWS_ACCESS_KEY_SECRET:
required: true
TF_VAR_DO_TOKEN:
required: false
GH_APPROVAL_APP_ID:
required: false
GH_APPROVAL_APP_PKEY:
required: false
OS_TENANT_ID:
required: false
OS_TENANT_NAME:
required: false
OS_USERNAME:
required: false
OS_PASSWORD:
required: false
OVH_APPLICATION_KEY:
required: false
OVH_APPLICATION_SECRET:
required: false
OVH_CONSUMER_KEY:
required: false
OVH_CLOUD_PROJECT_SERVICE:
required: false
TELEPORT_TOKEN:
required: false
description: Teleport Token name
VAULT_TOKEN:
required: false
description: A Vault token in case vault is required
PAT_GIT:
required: false
description: A PAT token to clone the repository
KNOWN_HOSTS:
required: false
description: A known hosts file to clone the repository
PRIVATE_SSH_KEY_TFMODULES:
required: false
description: A private SSH key to clone the repository
AZURE_CLIENT_ID:
required: false
description: "Azure Client ID"
AZURE_TENANT_ID:
required: false
description: "Azure Tenant ID"
AZURE_SUBSCRIPTION_ID:
required: false
description: "Azure Subscription ID"
env:
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
jobs:
terragrunt:
name: 'Terragrunt ${{ inputs.WORKING_DIR}}'
runs-on: ${{ inputs.RUNNER }}
environment:
name: ${{ inputs.ENVIRONMENT }}
permissions: write-all
steps:
- name: Install dependencies
run: |
sudo apt update
sudo apt install unzip git -yq
- name: cleanup old checkout
run: chmod +w -R ${GITHUB_WORKSPACE}; rm -rf ${GITHUB_WORKSPACE}/*;
- name: 'Checkout'
uses: actions/checkout@v4
- name: Checkout actions
uses: actions/checkout@v4
with:
repository: signalwire/actions-template
ref: main
path: actions
- name: Configure AWS Credentials
uses: aws-actions/[email protected]
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_ACCESS_KEY_SECRET }}
aws-region: ${{ inputs.AWS_REGION }}
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/[email protected]'
if: inputs.GCP_ENV == true
with:
workload_identity_provider: ${{ inputs.GCP_WIP }}
project_id: ${{ inputs.PROJECT_ID }}
service_account: ${{ inputs.GCP_SA }}
- name: Sops Binary Installer
uses: mdgreenwald/[email protected]
if: inputs.TELEPORT_APP != ''
with:
version: 3.7.3
- name: Authenticate against Teleport to use Vault
if: inputs.TELEPORT_APP != ''
id: teleportapp
uses: ./actions/.github/actions/teleport
env:
TOKEN: ${{ secrets.TELEPORT_TOKEN }}
PROXY_URL: ${{ inputs.TELEPORT_PROXY_URL }}
with:
TELEPORT_APP: ${{ inputs.TELEPORT_APP }}
- name: Configure Vault
if: inputs.TELEPORT_APP != ''
run: |
echo VAULT_ADDR=https://${{ inputs.TELEPORT_PROXY_URL }} >> $GITHUB_ENV
#echo VAULT_API_ADDR=https://${{ inputs.TELEPORT_PROXY_URL }} >> $GITHUB_ENV
echo VAULT_CLIENT_TIMEOUT=120s >> $GITHUB_ENV
cp ${{ steps.teleportapp.outputs.certificate-file }} ${{github.workspace}}/certificate-file
echo VAULT_CLIENT_CERT=${{github.workspace}}/certificate-file >> $GITHUB_ENV
cp ${{ steps.teleportapp.outputs.key-file }} ${{github.workspace}}/key-file
echo VAULT_CLIENT_KEY=${{github.workspace}}/key-file >> $GITHUB_ENV
echo VAULT_TOKEN=$VAULT_TOKEN >> $GITHUB_ENV
env:
VAULT_TOKEN: ${{ secrets.VAULT_TOKEN }}
- name: Init
id: init
uses: gruntwork-io/[email protected]
with:
tofu_version: ${{ inputs.TF_VERSION }}
tg_version: ${{ inputs.TG_VERSION }}
tg_dir: ./${{ inputs.WORKING_DIR }}
tg_command: 'run-all init'
env:
# configure git to use custom token to clone repository.
INPUT_PRE_EXEC_1: |
git config --global url."https://user:${{secrets.PAT_GIT}}@github.com".insteadOf "https://github.com"
# print git configuration
INPUT_PRE_EXEC_2: |
git config --global --list
- name: Validate
uses: gruntwork-io/[email protected]
id: validate
with:
tofu_version: ${{ inputs.TF_VERSION }}
tg_version: ${{ inputs.TG_VERSION }}
tg_dir: ${{ inputs.WORKING_DIR }}
tg_command: 'run-all validate'
env:
OVH_CLOUD_PROJECT_SERVICE: ${{ secrets.OVH_CLOUD_PROJECT_SERVICE }}
- name: Plan
uses: gruntwork-io/[email protected]
id: plan
continue-on-error: true
with:
tofu_version: ${{ inputs.TF_VERSION }}
tg_version: ${{ inputs.TG_VERSION }}
tg_dir: ${{ inputs.WORKING_DIR }}
tg_command: 'run-all plan'
tg_comment: 1
env:
TF_VAR_do_token: ${{ secrets.TF_VAR_DO_TOKEN }}
OS_AUTH_URL: https://auth.cloud.ovh.net/v3
OS_IDENTITY_API_VERSION: 3
OS_PROJECT_DOMAIN_NAME: Default
OS_USER_DOMAIN_NAME: Default
OVH_ENDPOINT: ovh-ca
OS_TENANT_ID: ${{ secrets.OS_TENANT_ID }}
OS_TENANT_NAME: ${{ secrets.OS_TENANT_NAME }}
OS_USERNAME: ${{ secrets.OS_USERNAME }}
OS_PASSWORD: ${{ secrets.OS_PASSWORD }}
OVH_APPLICATION_KEY: ${{ secrets.OVH_APPLICATION_KEY }}
OVH_APPLICATION_SECRET: ${{ secrets.OVH_APPLICATION_SECRET }}
OVH_CONSUMER_KEY: ${{ secrets.OVH_CONSUMER_KEY }}
OVH_CLOUD_PROJECT_SERVICE: ${{ secrets.OVH_CLOUD_PROJECT_SERVICE }}
GITHUB_TOKEN: ${{ github.token }}
# TF_LOG: trace
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v2
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
with:
app_id: ${{ secrets.GH_APPROVAL_APP_ID }}
private_key: ${{ secrets.GH_APPROVAL_APP_PKEY }}
- name: Wait for approval
uses: trstringer/manual-approval@v1
timeout-minutes: 60
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
with:
secret: ${{ steps.generate_token.outputs.token }}
approvers: ${{ inputs.APPROVERS }}
minimum-approvals: 1
issue-title: "Terragrunt approval pending for ${{ inputs.WORKING_DIR }}"
- name: Apply
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
uses: gruntwork-io/[email protected]
id: apply
with:
tofu_version: ${{ inputs.TF_VERSION }}
tg_version: ${{ inputs.TG_VERSION }}
tg_dir: ${{ inputs.WORKING_DIR }}
tg_command: 'run-all apply'
env:
TF_VAR_do_token: ${{ secrets.TF_VAR_DO_TOKEN }}
OS_AUTH_URL: https://auth.cloud.ovh.net/v3
OS_IDENTITY_API_VERSION: 3
OS_PROJECT_DOMAIN_NAME: Default
OS_USER_DOMAIN_NAME: Default
OVH_ENDPOINT: ovh-ca
OS_TENANT_ID: ${{ secrets.OS_TENANT_ID }}
OS_TENANT_NAME: ${{ secrets.OS_TENANT_NAME }}
OS_USERNAME: ${{ secrets.OS_USERNAME }}
OS_PASSWORD: ${{ secrets.OS_PASSWORD }}
OVH_APPLICATION_KEY: ${{ secrets.OVH_APPLICATION_KEY }}
OVH_APPLICATION_SECRET: ${{ secrets.OVH_APPLICATION_SECRET }}
OVH_CONSUMER_KEY: ${{ secrets.OVH_CONSUMER_KEY }}
OVH_CLOUD_PROJECT_SERVICE: ${{ secrets.OVH_CLOUD_PROJECT_SERVICE }}
- run: sudo chmod -R 777 /home/runner/_work/${{ github.event.repository.name }}
continue-on-error: true