-
Notifications
You must be signed in to change notification settings - Fork 7
577 lines (522 loc) · 31.8 KB
/
pipelines-root.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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
name: Pipelines
run-name: Run Gruntwork Pipelines
on:
workflow_call:
inputs:
# This field can be overriden to customize the runner used for pipelines
# workflows.
#
# IMPORTANT: To use self-hosted runners this workflow must be hosted in
# the same GitHub organization as your infra-live repository.
# See https://docs.github.com/en/actions/using-workflows/reusing-workflows#using-self-hosted-runners
#
# The value must be an escaped JSON string that will be decoded to the
# jobs.runs-on field
# See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idruns-on
#
# For example:
# - A simple github runner: "\"ubuntu-22.04\""
# - A list of labels: "[\"self-hosted\", \"linux\"]"
# - A map: "{group: \"ubuntu-runners\", labels: \"ubuntu-20.04-16core\"}"
runner:
type: string
default: '"ubuntu-latest"'
api_base_url:
type: string
default: "https://api.prod.app.gruntwork.io/api/v1"
secrets:
PIPELINES_READ_TOKEN:
required: true
INFRA_ROOT_WRITE_TOKEN:
required: true
ORG_REPO_ADMIN_TOKEN:
required: false
env:
PIPELINES_CLI_VERSION: v0.31.2
PIPELINES_ACTIONS_VERSION: v3.1.2
BOILERPLATE_VERSION: v0.5.16
GRUNTWORK_INSTALLER_VERSION: v0.0.40
# Disables all executions of terragrunt. This is useful for debugging
# specifics of pipelines actions/workflows and bypassing the (usually time consuming)
# actual IaC execution.
SKIP_TERRAGRUNT: false
# GitHub Actions tends to hit resource exhaustion and kill running jobs
# if we leave parallelism unbounded, so we set the max to 10 for a sane default.
TERRAGRUNT_PARALLELISM: 10
jobs:
pipelines_orchestrate:
name: Detect Infrastructure Changes
runs-on: ${{ fromJSON(inputs.runner) }}
steps:
- name: Record start time
id: start_time
run: |
time_now=$(date -u +"%s")
echo "PIPELINES_JOB_START_TIME=$time_now" >> $GITHUB_ENV
- name: Fetch Gruntwork Read Token
id: pipelines-gruntwork-read-token
uses: gruntwork-io/pipelines-credentials@v1
with:
PIPELINES_TOKEN_PATH: "pipelines-read/gruntwork-io"
FALLBACK_TOKEN: ${{ secrets.PIPELINES_READ_TOKEN }}
api_base_url: ${{ inputs.api_base_url }}
- name: Fetch Org Read Token
id: pipelines-customer-org-read-token
uses: gruntwork-io/pipelines-credentials@v1
with:
PIPELINES_TOKEN_PATH: pipelines-read/${{ github.repository_owner }}
FALLBACK_TOKEN: ${{ secrets.PIPELINES_READ_TOKEN }}
api_base_url: ${{ inputs.api_base_url }}
- name: Fetch Infra Root Write Token
id: pipelines-infra-root-write-token
uses: gruntwork-io/pipelines-credentials@v1
with:
PIPELINES_TOKEN_PATH: infra-root-write/${{ github.repository_owner }}
FALLBACK_TOKEN: ${{ secrets.INFRA_ROOT_WRITE_TOKEN }}
api_base_url: ${{ inputs.api_base_url }}
- name: Fetch Org Repo Admin Token
id: pipelines-org-repo-admin-token
uses: gruntwork-io/pipelines-credentials@v1
with:
PIPELINES_TOKEN_PATH: org-repo-admin/${{ github.repository_owner }}
FALLBACK_TOKEN: ${{ secrets.ORG_REPO_ADMIN_TOKEN }}
api_base_url: ${{ inputs.api_base_url }}
- name: Checkout Pipelines Actions
id: checkout_actions
uses: actions/checkout@v4
with:
path: pipelines-actions
repository: gruntwork-io/pipelines-actions
ref: ${{ env.PIPELINES_ACTIONS_VERSION }}
token: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
- name: Validate PIPELINES_READ_TOKEN
if: always() && steps.checkout_actions.conclusion != 'success'
env:
GH_TOKEN: ${{ github.token }}
GITHUB_ORG: ${{ github.repository }}
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
shell: bash
run: |
logs_url="https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
msg=$(printf "<h2>❌ Plan for $PR_HEAD_SHA</h2>❌ Gruntwork Pipelines was unable to checkout the <code>pipelines-actions</code> repository. Please ensure the <code>PIPELINES_READ_TOKEN</code> is valid and unexpired. <a href=\"https://docs.gruntwork.io/pipelines/security/machine-users#ci-read-only-user\">Learn More</a><br><br><br><a href=\"$logs_url\">View full logs</a>")
echo "::error:: $msg"
echo "$msg" >> "$GITHUB_STEP_SUMMARY"
pull_number=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
gh pr comment $pull_number -b "$msg" -R $GITHUB_ORG || true # || true incase this fails on a non-PR run
- name: Check out repo code
uses: actions/checkout@v4
with:
path: infra-live-repo
fetch-depth: 0
token: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
- name: Preflight Checks
uses: ./pipelines-actions/.github/actions/pipelines-preflight-action
with:
IS_ROOT: "true"
PIPELINES_READ_TOKEN: ${{ secrets.PIPELINES_READ_TOKEN }}
INFRA_ROOT_WRITE_TOKEN: ${{ steps.pipelines-infra-root-write-token.outputs.PIPELINES_TOKEN }}
ORG_REPO_ADMIN_TOKEN: ${{ steps.pipelines-org-repo-admin-token.outputs.PIPELINES_TOKEN }}
PIPELINES_GRUNTWORK_READ_TOKEN: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
PIPELINES_CUSTOMER_ORG_READ_TOKEN: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
PR_COMMENT_WRITE_TOKEN: ${{ steps.pipelines-infra-root-write-token.outputs.PIPELINES_TOKEN }}
- name: Pipelines Orchestrate
id: orchestrate
uses: ./pipelines-actions/.github/actions/pipelines-orchestrate
with:
PIPELINES_GRUNTWORK_READ_TOKEN: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
PIPELINES_CUSTOMER_ORG_READ_TOKEN: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
PR_COMMENT_WRITE_TOKEN: ${{ steps.pipelines-infra-root-write-token.outputs.PIPELINES_TOKEN }}
outputs:
pipelines_jobs: ${{ steps.orchestrate.outputs.jobs }}
pipelines_execute:
env:
JOB_NAME: ${{ contains(matrix.jobs.Action.Command, 'plan') && 'Plan' || 'Apply' }} - ${{ matrix.jobs.ChangeType }} - ${{ matrix.jobs.WorkingDirectory }}
name: ${{ contains(matrix.jobs.Action.Command, 'plan') && 'Plan' || 'Apply' }} - ${{ matrix.jobs.ChangeType }} - ${{ matrix.jobs.WorkingDirectory }}
needs: [pipelines_orchestrate]
runs-on: ${{ fromJSON(inputs.runner) }}
# GHA can't check for length, so we just check if there is an item in the 0 index
if: fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs)[0] != null
strategy:
fail-fast: false
matrix:
jobs: ${{ fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs) }}
steps:
- name: Record start time
id: start_time
run: |
time_now=$(date -u +"%s")
echo "PIPELINES_JOB_START_TIME=$time_now" >> $GITHUB_ENV
- name: Fetch Gruntwork Read Token
id: pipelines-gruntwork-read-token
uses: gruntwork-io/pipelines-credentials@v1
with:
PIPELINES_TOKEN_PATH: "pipelines-read/gruntwork-io"
FALLBACK_TOKEN: ${{ secrets.PIPELINES_READ_TOKEN }}
api_base_url: ${{ inputs.api_base_url }}
- name: Fetch Org Read Token
id: pipelines-customer-org-read-token
uses: gruntwork-io/pipelines-credentials@v1
with:
PIPELINES_TOKEN_PATH: pipelines-read/${{ github.repository_owner }}
FALLBACK_TOKEN: ${{ secrets.PIPELINES_READ_TOKEN }}
api_base_url: ${{ inputs.api_base_url }}
- name: Fetch Infra Root Write Token
id: pipelines-infra-root-write-token
uses: gruntwork-io/pipelines-credentials@v1
with:
PIPELINES_TOKEN_PATH: infra-root-write/${{ github.repository_owner }}
FALLBACK_TOKEN: ${{ secrets.INFRA_ROOT_WRITE_TOKEN }}
api_base_url: ${{ inputs.api_base_url }}
- name: Checkout Pipelines Actions
uses: actions/checkout@v4
with:
path: pipelines-actions
repository: gruntwork-io/pipelines-actions
ref: ${{ env.PIPELINES_ACTIONS_VERSION }}
token: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
- name: Check out repo code
uses: actions/checkout@v4
with:
path: infra-live-repo
fetch-depth: 0
token: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
- name: Bootstrap Workflow
id: gruntwork_context
uses: ./pipelines-actions/.github/actions/pipelines-bootstrap
with:
PIPELINES_GRUNTWORK_READ_TOKEN: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
PIPELINES_CUSTOMER_ORG_READ_TOKEN: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
change_type: ${{ matrix.jobs.ChangeType }}
branch: ${{ matrix.jobs.Ref }}
working_directory: ${{ matrix.jobs.WorkingDirectory }}
account_id: ${{ matrix.jobs.AccountId }}
terragrunt_command: ${{ matrix.jobs.Action.Command }} ${{ matrix.jobs.Action.Args }}
additional_data: ${{ toJson(matrix.jobs.AdditionalData) }}
child_account_id: ${{ matrix.jobs.AdditionalData.ChildAccountId }}
account_names: ${{ matrix.jobs.AdditionalData.AccountNames }}
# TODO: This should be "first_new_account_name".
new_account_name: ${{ matrix.jobs.NewAccounts[0].Name }}
# To learn more about customizing Pipelines see our documentation at https://docs.gruntwork.io/pipelines/maintain/extending/
- name: "[Baseline]: Pre Provision New Account Custom Action"
uses: ./pipelines-actions/.github/custom-actions/pre-provision-new-account
if: ${{ steps.gruntwork_context.outputs.action == 'PROVISION_ACCOUNT' }}
with:
PIPELINES_GRUNTWORK_READ_TOKEN: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
PIPELINES_CUSTOMER_ORG_READ_TOKEN: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
INFRA_ROOT_WRITE_TOKEN: ${{ steps.pipelines-infra-root-write-token.outputs.PIPELINES_TOKEN }}
gruntwork_context: ${{ toJson(steps.gruntwork_context.outputs) }}
- name: "[ProvisionAccount]: Provision New Account"
id: provision_new_account
if: ${{ steps.gruntwork_context.outputs.action == 'PROVISION_ACCOUNT' }}
uses: ./pipelines-actions/.github/actions/pipelines-provision-account-action
with:
PIPELINES_GRUNTWORK_READ_TOKEN: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
PIPELINES_CUSTOMER_ORG_READ_TOKEN: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
PR_COMMENT_WRITE_TOKEN: ${{ steps.pipelines-infra-root-write-token.outputs.PIPELINES_TOKEN }}
gruntwork_context: ${{ toJson(steps.gruntwork_context.outputs) }}
- name: "[ProvisionAccount]: Post Provision New Account Custom Action"
uses: ./pipelines-actions/.github/custom-actions/post-provision-new-account
if: ${{ steps.gruntwork_context.outputs.action == 'PROVISION_ACCOUNT' }}
with:
PIPELINES_GRUNTWORK_READ_TOKEN: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
PIPELINES_CUSTOMER_ORG_READ_TOKEN: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
INFRA_ROOT_WRITE_TOKEN: ${{ steps.pipelines-infra-root-write-token.outputs.PIPELINES_TOKEN }}
gruntwork_context: ${{ toJson(steps.gruntwork_context.outputs) }}
baseline_path: ${{ steps.provision_new_account.outputs.baseline_path }}
- name: "[ProvisionAccount]: Create New Account Pull Request Action"
uses: ./pipelines-actions/.github/actions/pipelines-new-pr-action
if: ${{ steps.gruntwork_context.outputs.action == 'PROVISION_ACCOUNT' }}
with:
GH_TOKEN: ${{ steps.pipelines-infra-root-write-token.outputs.PIPELINES_TOKEN }}
path: ${{ steps.provision_new_account.outputs.baseline_path }}
new_branch_name: ${{ steps.provision_new_account.outputs.new_branch_name }}
commit_message: ${{ steps.provision_new_account.outputs.commit_message }}
pr_body: ${{ steps.provision_new_account.outputs.pr_body }}
requesting_pr_number: ${{ steps.provision_new_account.outputs.requesting_pr_number }}
step_summary_content: ${{ steps.provision_new_account.outputs.step_summary_content }}
gruntwork_context: ${{ toJson(steps.gruntwork_context.outputs) }}
- name: "[Baseline]: Pre Baseline Core Account Action"
uses: ./pipelines-actions/.github/custom-actions/pre-baseline-core-accounts
if: steps.gruntwork_context.outputs.action == 'BASELINE_ACCOUNT'
with:
PIPELINES_GRUNTWORK_READ_TOKEN: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
PIPELINES_CUSTOMER_ORG_READ_TOKEN: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
gruntwork_context: ${{ toJson(steps.gruntwork_context.outputs) }}
# Run the core accounts baselines(shared, logs, security, etc. to ensure the account is setup correctly)
- name: "Run core accounts baselines"
id: core_accounts_baselines
if: steps.gruntwork_context.outputs.action == 'BASELINE_ACCOUNT'
# TODO: Rename this as pipelines-apply-core-baselines or something similar
uses: ./pipelines-actions/.github/actions/pipelines-baseline-account-action
with:
PIPELINES_GRUNTWORK_READ_TOKEN: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
PIPELINES_CUSTOMER_ORG_READ_TOKEN: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
PR_COMMENT_WRITE_TOKEN: ${{ steps.pipelines-infra-root-write-token.outputs.PIPELINES_TOKEN }}
gruntwork_context: ${{ toJson(steps.gruntwork_context.outputs) }}
- name: "[Baseline]: Post Baseline Core Account Action"
uses: ./pipelines-actions/.github/custom-actions/post-baseline-core-accounts
if: steps.gruntwork_context.outputs.action == 'BASELINE_ACCOUNT'
with:
PIPELINES_GRUNTWORK_READ_TOKEN: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
PIPELINES_CUSTOMER_ORG_READ_TOKEN: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
gruntwork_context: ${{ toJson(steps.gruntwork_context.outputs) }}
- name: "[TerragruntExecute]: Authenticate with AWS and then Invoke Terragrunt"
id: terragrunt
if: ${{ steps.gruntwork_context.outputs.action == 'TERRAGRUNT_EXECUTE' }}
uses: ./pipelines-actions/.github/actions/pipelines-execute
env:
TERRAGRUNT_AUTH_PROVIDER_CMD: "pipelines auth terragrunt-credentials --ci github-actions --cloud aws --wd . --disk-cache-duration-minutes 10"
with:
PIPELINES_GRUNTWORK_READ_TOKEN: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
PIPELINES_CUSTOMER_ORG_READ_TOKEN: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
tf_binary: ${{ steps.gruntwork_context.outputs.tf_binary }}
working_directory: ${{ steps.gruntwork_context.outputs.working_directory }}
terragrunt_command: ${{ steps.gruntwork_context.outputs.terragrunt_command }}
infra_live_repo_branch: ${{ steps.gruntwork_context.outputs.branch }}
gruntwork_config_file: ${{ steps.gruntwork_context.outputs.gruntwork_config_file }}
infra_live_repo: "."
infra_live_directory: "."
deploy_branch_name: ${{ steps.gruntwork_context.outputs.deploy_branch_name }}
- name: Get Logs URL
id: get_logs_url
uses: ./pipelines-actions/.github/actions/pipelines-get-job-logs-url
if: always()
with:
PIPELINES_CUSTOMER_ORG_READ_TOKEN: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
job_name: ${{ env.JOB_NAME }}
step_name_prefix: "${{ steps.gruntwork_context.outputs.action == 'TERRAGRUNT_EXECUTE' && '[TerragruntExecute]:\ Authenticate with AWS and then Invoke Terragrunt' || (steps.gruntwork_context.outputs.action == 'BASELINE_ACCOUNT' && 'Run core accounts baselines' || '[ProvisionAccount]:\ Provision New Account') }}"
- name: Update comment
uses: ./pipelines-actions/.github/actions/pipelines-status-update
if: always()
with:
step_name: ${{ matrix.jobs.ChangeType }}
step_working_directory: ${{ matrix.jobs.WorkingDirectory }}
step_status: ${{ (steps.provision_new_account.conclusion == 'success' || steps.terragrunt.conclusion == 'success' || steps.core_accounts_baselines.conclusion == 'success') && 'success' || 'failed' }}
step_details: ${{ steps.terragrunt.outputs.formatted_plan_output }}
step_details_extended_log: ${{ steps.terragrunt.outputs.execute_stdout_log }}
pull_request_number: ${{ steps.gruntwork_context.outputs.pr_number }}
step_logs_url: ${{ steps.get_logs_url.outputs.step_logs_url }}
PR_COMMENT_WRITE_TOKEN: ${{ steps.pipelines-infra-root-write-token.outputs.PIPELINES_TOKEN }}
outputs:
account_id: ${{ matrix.jobs.AccountId }}
branch: ${{ steps.gruntwork_context.outputs.branch }}
action: ${{ steps.gruntwork_context.outputs.action }}
working_directory: ${{ steps.gruntwork_context.outputs.working_directory }}
terragrunt_command: ${{ steps.gruntwork_context.outputs.terragrunt_command }}
additional_data: ${{ steps.gruntwork_context.outputs.additional_data }}
child_account_id: ${{ steps.gruntwork_context.outputs.child_account_id }}
pr_number: ${{ steps.gruntwork_context.outputs.pr_number }}
delegate_management: ${{ steps.gruntwork_context.outputs.delegate_management }}
pipelines_apply_baselines:
env:
JOB_NAME: Baseline Child Account ${{ contains(fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs)[0].Action.Command, 'plan') && 'Plan' || 'Apply' }} - ${{ matrix.jobs.Name }} (${{ matrix.jobs.ID }})
name: Baseline Child Account ${{ contains(fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs)[0].Action.Command, 'plan') && 'Plan' || 'Apply' }} - ${{ matrix.jobs.Name }} (${{ matrix.jobs.ID }})
needs: [pipelines_orchestrate, pipelines_execute]
runs-on: ${{ fromJSON(inputs.runner) }}
# GHA can't check for length, so we just check if there is an item in the 0 index
if: fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs)[0].NewAccounts[0] != null
strategy:
fail-fast: false
matrix:
jobs: ${{ fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs)[0].NewAccounts }}
steps:
- name: Fetch Gruntwork Read Token
id: pipelines-gruntwork-read-token
uses: gruntwork-io/pipelines-credentials@v1
with:
PIPELINES_TOKEN_PATH: "pipelines-read/gruntwork-io"
FALLBACK_TOKEN: ${{ secrets.PIPELINES_READ_TOKEN }}
api_base_url: ${{ inputs.api_base_url }}
- name: Fetch Org Read Token
id: pipelines-customer-org-read-token
uses: gruntwork-io/pipelines-credentials@v1
with:
PIPELINES_TOKEN_PATH: pipelines-read/${{ github.repository_owner }}
FALLBACK_TOKEN: ${{ secrets.PIPELINES_READ_TOKEN }}
api_base_url: ${{ inputs.api_base_url }}
- name: Fetch Create PR Token
id: pipelines-propose-infra-change-token
uses: gruntwork-io/pipelines-credentials@v1
with:
PIPELINES_TOKEN_PATH: propose-infra-change/${{ github.repository_owner }}
FALLBACK_TOKEN: ${{ secrets.INFRA_ROOT_WRITE_TOKEN }}
api_base_url: ${{ inputs.api_base_url }}
- name: Checkout Pipelines Actions
uses: actions/checkout@v4
with:
path: pipelines-actions
repository: gruntwork-io/pipelines-actions
ref: ${{ env.PIPELINES_ACTIONS_VERSION }}
token: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
- name: Check out repo code
uses: actions/checkout@v4
with:
path: infra-live-repo
fetch-depth: 0
token: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
- name: Update comment
uses: ./pipelines-actions/.github/actions/pipelines-status-update
with:
step_name: Baseline Child Account ${{ matrix.jobs.Name }}
step_status: "in_progress"
pull_request_number: ${{ needs.pipelines_execute.outputs.pr_number }}
PR_COMMENT_WRITE_TOKEN: ${{ steps.pipelines-propose-infra-change-token.outputs.PIPELINES_TOKEN }}
- name: Bootstrap Workflow
id: gruntwork_context
uses: ./pipelines-actions/.github/actions/pipelines-bootstrap
with:
PIPELINES_GRUNTWORK_READ_TOKEN: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
PIPELINES_CUSTOMER_ORG_READ_TOKEN: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
change_type: ${{ fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs)[0].ChangeType }}
branch: ${{ fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs)[0].Ref }}
working_directory: ${{ fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs)[0].WorkingDirectory }}
account_id: ${{ fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs)[0].AccountId }}
terragrunt_command: ${{ fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs)[0].Action.Command }} ${{ fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs)[0].Action.Args }}
additional_data: ${{ toJson(fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs)[0].AdditionalData) }}
account_names: ${{ fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs)[0].AdditionalData.AccountNames }}
child_account_id: ${{ matrix.jobs.ID }}
new_account_name: ${{ matrix.jobs.Name }}
# To learn more about customizing Pipelines see our documentation at https://docs.gruntwork.io/pipelines/maintain/extending/
- name: "[Baseline]: Pre Baseline Child Account Action"
uses: ./pipelines-actions/.github/custom-actions/pre-baseline-child-account
with:
PIPELINES_GRUNTWORK_READ_TOKEN: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
PIPELINES_CUSTOMER_ORG_READ_TOKEN: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
account_id: ${{ matrix.jobs.ID }}
account_name: ${{ matrix.jobs.Name }}
job: ${{ toJson(fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs)[0]) }}
gruntwork_context: ${{ toJson(steps.gruntwork_context.outputs) }}
- name: "[Baseline]: Baseline the Child Account"
id: baseline_child_account
uses: ./pipelines-actions/.github/actions/pipelines-baseline-child-account-action
with:
PIPELINES_GRUNTWORK_READ_TOKEN: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
PIPELINES_CUSTOMER_ORG_READ_TOKEN: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
account_id: ${{ matrix.jobs.ID }}
account_name: ${{ matrix.jobs.Name }}
job: ${{ toJson(fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs)[0]) }}
gruntwork_context: ${{ toJson(steps.gruntwork_context.outputs) }}
- name: "[Baseline]: Post Baseline Child Account Action"
uses: ./pipelines-actions/.github/custom-actions/post-baseline-child-account
with:
PIPELINES_GRUNTWORK_READ_TOKEN: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
PIPELINES_CUSTOMER_ORG_READ_TOKEN: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
account_id: ${{ matrix.jobs.ID }}
account_name: ${{ matrix.jobs.Name }}
job: ${{ toJson(fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs)[0]) }}
gruntwork_context: ${{ toJson(steps.gruntwork_context.outputs) }}
- name: Get Logs URL
id: get_logs_url
uses: ./pipelines-actions/.github/actions/pipelines-get-job-logs-url
if: always()
with:
PIPELINES_CUSTOMER_ORG_READ_TOKEN: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
job_name: ${{ env.JOB_NAME }}
step_name_prefix: "[Baseline]: Baseline the Child Account"
- name: Update comment
uses: ./pipelines-actions/.github/actions/pipelines-status-update
if: always()
with:
step_name: Baseline Child Account ${{ matrix.jobs.Name }}
step_status: ${{ steps.baseline_child_account.conclusion == 'success' && 'success' || 'failed' }}
step_details: ${{ steps.baseline_child_account.outputs.formatted_plan_output || 'Check the logs for more details.' }}
step_details_extended_log: ${{ steps.baseline_child_account.outputs.execute_stdout_log }}
pull_request_number: ${{ needs.pipelines_execute.outputs.pr_number }}
step_logs_url: ${{ steps.get_logs_url.outputs.step_logs_url }}
PR_COMMENT_WRITE_TOKEN: ${{ steps.pipelines-propose-infra-change-token.outputs.PIPELINES_TOKEN }}
pipelines_setup_delegated_repo:
name: "Setup Delegated Repo"
needs: [pipelines_orchestrate, pipelines_apply_baselines, pipelines_execute]
runs-on: ${{ fromJSON(inputs.runner) }}
# GHA can't check for length, so we just check if there is an item in the 0 index
if: ${{ fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs)[0].NewAccounts[0] != null && needs.pipelines_execute.outputs.delegate_management == 'true' && needs.pipelines_execute.outputs.terragrunt_command == 'run-all apply' }}
steps:
- name: Fetch Gruntwork Read Token
id: pipelines-gruntwork-read-token
uses: gruntwork-io/pipelines-credentials@v1
with:
PIPELINES_TOKEN_PATH: "pipelines-read/gruntwork-io"
FALLBACK_TOKEN: ${{ secrets.PIPELINES_READ_TOKEN }}
api_base_url: ${{ inputs.api_base_url }}
- name: Fetch Org Read Token
id: pipelines-customer-org-read-token
uses: gruntwork-io/pipelines-credentials@v1
with:
PIPELINES_TOKEN_PATH: pipelines-read/${{ github.repository_owner }}
FALLBACK_TOKEN: ${{ secrets.PIPELINES_READ_TOKEN }}
api_base_url: ${{ inputs.api_base_url }}
- name: Fetch Org Repo Admin Token
id: pipelines-org-repo-admin-token
uses: gruntwork-io/pipelines-credentials@v1
with:
PIPELINES_TOKEN_PATH: org-repo-admin/${{ github.repository_owner }}
FALLBACK_TOKEN: ${{ secrets.ORG_REPO_ADMIN_TOKEN }}
api_base_url: ${{ inputs.api_base_url }}
- name: Checkout Pipelines Actions
uses: actions/checkout@v4
with:
path: pipelines-actions
repository: gruntwork-io/pipelines-actions
ref: ${{ env.PIPELINES_ACTIONS_VERSION }}
token: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
- name: Check out repo code
uses: actions/checkout@v4
with:
path: infra-live-repo
fetch-depth: 0
token: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
- name: Bootstrap Workflow
id: gruntwork_context
uses: ./pipelines-actions/.github/actions/pipelines-bootstrap
with:
PIPELINES_GRUNTWORK_READ_TOKEN: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
PIPELINES_CUSTOMER_ORG_READ_TOKEN: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
change_type: ${{ fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs)[0].ChangeType }}
branch: ${{ fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs)[0].Ref }}
working_directory: ${{ fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs)[0].WorkingDirectory }}
account_id: ${{ fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs)[0].AccountId }}
terragrunt_command: ${{ fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs)[0].Action.Command }} ${{ needs.pipelines_orchestrate.outputs.pipelines_jobs[0].Action.Args }}
additional_data: ${{ toJson(fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs)[0].AdditionalData) }}
child_account_id: ${{ fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs)[0].AdditionalData.ChildAccountId }}
account_names: ${{ fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs)[0].AdditionalData.AccountNames }}
# This is just to help bootstrap find one of the (possibly several) new account request files
# Inside those files is some shared config that we need to setup access control such as
# the delegated_repo_name (which is the same in all the new request files)
new_account_name: ${{ fromJson(needs.pipelines_orchestrate.outputs.pipelines_jobs)[0].NewAccounts[0].Name }}
- name: "Create Access Control PR"
id: access_control_pr
uses: ./pipelines-actions/.github/actions/pipelines-provision-access-control-action
with:
gruntwork_context: ${{ toJson(steps.gruntwork_context.outputs) }}
PIPELINES_GRUNTWORK_READ_TOKEN: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
PIPELINES_CUSTOMER_ORG_READ_TOKEN: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
ORG_REPO_ADMIN_TOKEN: ${{ steps.pipelines-org-repo-admin-token.outputs.PIPELINES_TOKEN }}
- name: "Create and bootstrap delegated Repo"
id: provision_delegated_repo
uses: ./pipelines-actions/.github/actions/pipelines-provision-repo-action
with:
gruntwork_context: ${{ toJson(steps.gruntwork_context.outputs) }}
access_control_pull_request_url: ${{ steps.access_control_pr.outputs.pull_request_url }}
PIPELINES_GRUNTWORK_READ_TOKEN: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
PIPELINES_CUSTOMER_ORG_READ_TOKEN: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
ORG_REPO_ADMIN_TOKEN: ${{ steps.pipelines-org-repo-admin-token.outputs.PIPELINES_TOKEN }}
# To learn more about customizing Pipelines see our documentation at https://docs.gruntwork.io/pipelines/maintain/extending/
- name: "Post create delegated repo custom actions"
uses: ./pipelines-actions/.github/custom-actions/post-create-delegated-repo
with:
gruntwork_context: ${{ toJson(steps.gruntwork_context.outputs) }}
access_control_pull_request_url: ${{ steps.access_control_pr.outputs.pull_request_url }}
PIPELINES_GRUNTWORK_READ_TOKEN: ${{ steps.pipelines-gruntwork-read-token.outputs.PIPELINES_TOKEN }}
PIPELINES_CUSTOMER_ORG_READ_TOKEN: ${{ steps.pipelines-customer-org-read-token.outputs.PIPELINES_TOKEN }}
ORG_REPO_ADMIN_TOKEN: ${{ steps.pipelines-org-repo-admin-token.outputs.PIPELINES_TOKEN }}
- name: "Create Delegated Repo PR"
uses: ./pipelines-actions/.github/actions/pipelines-new-pr-action
with:
gruntwork_context: ${{ toJson(steps.gruntwork_context.outputs) }}
GH_TOKEN: ${{ steps.pipelines-org-repo-admin-token.outputs.PIPELINES_TOKEN }}
path: ${{ steps.provision_delegated_repo.outputs.path }}
new_branch_name: ${{ steps.provision_delegated_repo.outputs.new_branch_name }}
commit_message: ${{ steps.provision_delegated_repo.outputs.commit_message }}
pr_body: ${{ steps.provision_delegated_repo.outputs.pr_body }}
requesting_pr_number: ${{ steps.provision_delegated_repo.outputs.requesting_pr_number }}
step_summary_content: ${{ steps.provision_delegated_repo.outputs.step_summary_content }}