-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (84 loc) · 2.7 KB
/
ci-terraform-shared.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
name: "CI for PR (Terraform/Shared)"
on:
pull_request:
branches:
- main
paths:
- "terraform/shared/**"
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: "Setup Terraform"
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.9.8
terraform_wrapper: false
- name: "Terraform Format"
id: fmt
working-directory: ./test/integration
run: make format-check-shared
- name: "Terraform Init"
id: init
working-directory: ./test/integration
run: make init-shared
- 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-shared
# Exit this job if tflint fails
- name: "Terraform Validate"
id: validate
working-directory: ./test/integration
run: make validate-shared
- name: "Terraform Plan"
id: plan
working-directory: ./test/integration
run: make plan-shared
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 (Shared)
#### 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
})