-
Notifications
You must be signed in to change notification settings - Fork 2
115 lines (93 loc) · 3.12 KB
/
tflint.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
name: tflint
on:
pull_request:
paths:
- 'terraform/**'
- .github/workflows/tflint.yml
- .tflint.hcl
- '!**/README.md'
push:
paths:
- 'terraform/**'
- .github/workflows/tflint.yml
- .tflint.hcl
- '!**/README.md'
workflow_dispatch:
env:
terraform_version: 1.5.3
tflint_version: v0.47.0
jobs:
pre-commit:
runs-on: ubuntu-22.04
permissions:
contents: read
steps:
- name: Checkout source code
uses: actions/checkout@v3
- name: Cache TFLint plugin dir
uses: actions/cache@v3
with:
path: ~/.tflint.d/plugins
key: tflint-${{ hashFiles('.tflint.hcl') }}
- name: Setup TFLint
uses: terraform-linters/setup-tflint@v3
with:
tflint_version: ${{ env.tflint_version }}
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: ${{ env.terraform_version }}
terraform_wrapper: false
- name: Cache Pre-commit dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pre-commit
key: cache-pre-commit-${{ hashFiles('.pre-commit-config.yaml','~/.cache/pre-commit/*') }}
- name: Run pre-commit
uses: pre-commit/[email protected]
with:
extra_args: --from-ref origin/master --to-ref HEAD
tflint:
runs-on: ubuntu-22.04
steps:
- name: Checkout source code
uses: actions/checkout@v3
- name: Cache plugin dir
uses: actions/cache@v3
with:
path: ~/.tflint.d/plugins
key: ${{ matrix.os }}-tflint-${{ hashFiles('.tflint.hcl') }}
- name: Setup TFLint
uses: terraform-linters/[email protected]
with:
tflint_version: v0.47.0
- name: Setup Terraform
uses: hashicorp/[email protected]
with:
terraform_version: ${{ env.terraform_version }}
terraform_wrapper: false
- name: Check Terraform formatting
working-directory: terraform
run: terraform fmt -recursive -check=true -write=false
- name: Init TFLint
run: tflint --init
env:
# https://github.com/terraform-linters/tflint/blob/master/docs/user-guide/plugins.md#avoiding-rate-limiting
GITHUB_TOKEN: ${{ github.token }}
- name: Run TFLint
shell: bash
run: |
top_dir="$(pwd)"
for d in $(find ./terraform -type d -print | sed -E 's|^./||' | grep -v "^terraform$" | sort); do
echo "Checking directory ${d}"
# Skip directory if no Terraform files found
ls ${d}/*.tf >/dev/null 2>&1 || { echo "No Terraform files found, skipping..."; continue; }
echo "Run Terraform init"
terraform -chdir="${d}" init -upgrade -backend=false
echo "Validate Terraform config"
terraform validate
echo "Run tflint"
tflint --chdir="${d}" --color --config="${top_dir}/.tflint.hcl"
done
- name: Check Terraform formatting
run: terraform -chdir=terraform fmt -recursive -check=true -write=false