-
Notifications
You must be signed in to change notification settings - Fork 19
76 lines (70 loc) · 2.6 KB
/
diff-cdktf-stacks.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
name: "Diff CDKTF Stack"
on:
workflow_call:
inputs:
stacks:
required: true
description: JSON-stringified list of stacks to deploy, e.g. # [{ "stack": "my-stack" }]
type: string
jobs:
terraform:
name: "Terraform CDK Diff"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix: ${{fromJSON(inputs.stacks)}}
max-parallel: 10
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Setup Terraform
uses: hashicorp/setup-terraform@a1502cd9e758c50496cc9ac5308c4843bcd56d36
with:
terraform_version: 1.6.6
cli_config_credentials_token: ${{ secrets.TF_CLOUD_TOKEN }}
terraform_wrapper: false
- name: Setup Node.js
uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1
with:
node-version: "18"
- name: Install
run: yarn install
- name: Synth
run: "$(yarn bin)/cdktf synth"
- name: Plan
id: plan
run: |
set -o pipefail
cd cdktf.out/stacks/${{ matrix.stack }}
rm -rf .terraform
terraform init
terraform plan -no-color | tee ../../../plan_stdout_${{ matrix.stack }}.txt; echo $?
set +o pipefail
continue-on-error: true
- name: Save results into a variable
id: plan_outcome
run: echo "value=${{steps.plan.outcome}}" >> $GITHUB_OUTPUT
- name: Comment the plan output on the PR
if: contains(github.event_name, 'pull_request') # pull_request or pull_request_target
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
github-token: ${{ secrets.GH_COMMENT_TOKEN }}
script: |
const {resolve} = require('path')
const scriptPath = resolve("./.github/lib/comment-plan-output")
require(scriptPath)({
context,
github,
planOutcome: "${{steps.plan.outcome}}",
pusher: "${{github.actor}}",
actionName: "${{github.event_name}}",
workingDirectory: "${{env.tf_actions_working_dir}}",
workflowName: "${{github.workflow}}",
stackName: "${{matrix.stack}}"
})
- name: Fail this check if the plan was not successful
if: steps.plan_outcome.outputs.value != 'success'
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
core.setFailed('Terraform plan was not successful')