-
Notifications
You must be signed in to change notification settings - Fork 3
153 lines (129 loc) · 4.35 KB
/
ci-check-infra.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
name: Infra - Check
on:
workflow_call:
inputs:
stage:
description: 'The name of the Terraform workspace to use'
type: string
required: true
tf-directory:
description: 'The directory containing the Terraform files'
type: string
default: ${{ vars.TF_DIRECTORY }}
run-label:
description: 'The run label to use for the actions'
type: string
default: 'ubuntu-latest'
secrets:
TF_API_TOKEN:
required: true
permissions:
contents: read
env:
TF_API_TOKEN: ${{ secrets.TF_API_TOKEN }}
TF_WORKSPACE: wl-${{ inputs.stage }}
jobs:
check-fmt:
name: Formatting
runs-on: ${{ inputs.run-label }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
token: ${{ secrets.PRIVATE_SUBMODULE_ACCESS_TOKEN || github.token }}
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
- name: Check Formatting
working-directory: ${{ inputs.tf-directory }}
run: terraform fmt -recursive -check
validate:
name: Validate
runs-on: ${{ inputs.run-label }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
token: ${{ secrets.PRIVATE_SUBMODULE_ACCESS_TOKEN || github.token }}
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
- name: Cache Terraform data
uses: actions/cache@v4
with:
path: ${{ inputs.tf-directory }}/.terraform
key: terraform-${{ hashFiles('${{ inputs.tf-directory }}/.terraform.lock.hcl') }}
- name: Init Terraform
working-directory: ${{ inputs.tf-directory }}
run: terraform init -no-color
- name: Validate Terraform
working-directory: ${{ inputs.tf-directory }}
run: terraform validate
tfsec:
name: TFSec
runs-on: ${{ inputs.run-label }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
token: ${{ secrets.PRIVATE_SUBMODULE_ACCESS_TOKEN || github.token }}
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
- name: Cache Terraform data
uses: actions/cache@v4
with:
path: ${{ inputs.tf-directory }}/.terraform
key: terraform-${{ hashFiles('${{ inputs.tf-directory }}/.terraform.lock.hcl') }}
- name: Init Terraform
working-directory: ${{ inputs.tf-directory }}
run: terraform init -no-color
- uses: aquasecurity/[email protected]
with:
working_directory: ${{ inputs.tf-directory }}
github_token: ${{ secrets.GITHUB_TOKEN }}
additional_args: '--exclude aws-ecs-enable-container-insight'
tflint:
name: TFLint
runs-on: ${{ inputs.run-label }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
token: ${{ secrets.PRIVATE_SUBMODULE_ACCESS_TOKEN || github.token }}
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
- name: Cache Terraform data
uses: actions/cache@v4
with:
path: ${{ inputs.tf-directory }}/.terraform
key: terraform-${{ hashFiles('${{ inputs.tf-directory }}/.terraform.lock.hcl') }}
- name: Init Terraform
working-directory: ${{ inputs.tf-directory }}
run: terraform init -no-color
- name: Setup TFLint
uses: terraform-linters/setup-tflint@v4
with:
tflint_version: v0.45.0
- name: Cache `tflint` plugins
uses: actions/cache@v4
with:
path: ~/.tflint.d/plugins
key: tflint-${{ hashFiles('${{ inputs.tf-directory }}/.tflint.hcl') }}
- name: Init TFLint
run: tflint --init
working-directory: ${{ inputs.tf-directory }}
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Check
run: tflint --recursive --format=compact
working-directory: ${{ inputs.tf-directory }}