Skip to content

Commit d52950a

Browse files
feat(ci): improve CI validations (#121)
Improve CI tests run against PRs: - Do `terraform init` and `terraform validate` - Check is `terraform fmt` shows any changes - Bump linter to newer version with more checks
1 parent 73fe24d commit d52950a

File tree

2 files changed

+73
-41
lines changed

2 files changed

+73
-41
lines changed

.github/workflows/lint.yaml

Lines changed: 0 additions & 41 deletions
This file was deleted.

.github/workflows/validate.yaml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Validate and lint
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
jobs:
9+
terraform_validation:
10+
strategy:
11+
matrix:
12+
version: ["1.11", latest]
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Terraform
20+
uses: hashicorp/setup-terraform@v3
21+
with:
22+
terraform_version: ${{ matrix.version }}
23+
24+
- name: Print tf version
25+
run: terraform version
26+
27+
- name: Terraform init
28+
run: "terraform init || terraform init -upgrade"
29+
30+
- name: Terraform validate
31+
run: "terraform validate"
32+
33+
- name: Terraform fmt
34+
run: |
35+
terraform fmt
36+
if [ -n "$(git status --porcelain)" ]; then
37+
echo "ERROR: terraform fmt resulted in changes. Run 'terraform fmt' locally and append the changes."
38+
echo
39+
git diff
40+
echo
41+
git status
42+
exit 1
43+
fi
44+
45+
tflint:
46+
runs-on: ubuntu-latest
47+
48+
steps:
49+
- uses: actions/checkout@v3
50+
name: Checkout source code
51+
52+
- uses: actions/cache@v3
53+
name: Cache plugin dir
54+
with:
55+
path: ~/.tflint.d/plugins
56+
key: tflint-${{ hashFiles('.tflint.hcl') }}
57+
58+
- uses: terraform-linters/setup-tflint@v1
59+
name: Setup TFLint
60+
with:
61+
tflint_version: v0.60.0
62+
63+
- name: Show version
64+
run: tflint --version
65+
66+
- name: Init TFLint
67+
run: tflint --init
68+
env:
69+
# https://github.com/terraform-linters/tflint/blob/master/docs/user-guide/plugins.md#avoiding-rate-limiting
70+
GITHUB_TOKEN: ${{ github.token }}
71+
72+
- name: Run TFLint
73+
run: tflint -f compact

0 commit comments

Comments
 (0)