-
Notifications
You must be signed in to change notification settings - Fork 0
136 lines (113 loc) · 3.74 KB
/
ci-terraform-blue.yaml
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
name: "CI for PR (Terraform/Blue)"
on:
pull_request:
branches:
- main
paths:
- "terraform/blue/**"
workflow_dispatch:
defaults:
run:
shell: bash
permissions:
contents: read
id-token: write
issues: write
pull-requests: write
jobs:
ci:
name: "CI"
runs-on: ubuntu-latest
env:
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
steps:
- name: "Checkout"
uses: actions/checkout@v4
- name: "Diff files"
id: diff
working-directory: ./test/integration/scripts
shell: bash -x {0}
continue-on-error: true
run: |
echo 'DIFF_LOG<<EOF' >> $GITHUB_ENV
./diff-terraform.sh >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
- name: "Create comment for PR (diff Terraform files between Blue & Green)"
uses: actions/github-script@v7
env:
DIFF: "${{ env.DIFF_LOG }}"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `#### Diff Terraform files between Blue & Green
<details><summary>Show Diff</summary>
\`\`\`\n
${process.env.DIFF}
\`\`\`
</details>
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
- name: "Setup Terraform"
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.10.1
terraform_wrapper: false
- name: "Terraform Format"
id: fmt
working-directory: ./test/integration
run: make format-check-blue
- name: "Terraform Init"
id: init
working-directory: ./test/integration
run: make init-blue
- name: "Setup TFLint"
uses: terraform-linters/setup-tflint@v4
with:
tflint_version: v0.54.0
- name: "Run TFLint"
id: tflint
working-directory: ./test/integration
run: make lint-blue
# Exit this job if tflint fails
- name: "Terraform Validate"
id: validate
working-directory: ./test/integration
run: make validate-blue
- name: "Terraform Plan"
id: plan
working-directory: ./test/integration
run: make plan-blue
continue-on-error: true
- name: "Create comment for PR (Terraform fmt/init/validate/plan)"
uses: actions/github-script@v7
env:
PLAN: "${{ steps.plan.outputs.stdout }}\n${{ steps.plan.outputs.stderr }}"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `#### Check Terraform files (Blue)
#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
#### TFLint 👓\`${{ steps.tflint.outcome }}\`
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
</details>
<details><summary>Show Plan</summary>
\`\`\`\n
${process.env.PLAN}
\`\`\`
</details>
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})