-
Notifications
You must be signed in to change notification settings - Fork 0
87 lines (73 loc) · 2.29 KB
/
terraform-ci.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
name: "Terraform CI checks"
permissions:
pull-requests: write
on:
push:
branches:
- main
paths:
- modules/**/*.tf
pull_request:
branches:
- main
paths:
- modules/**/*.tf
jobs:
terraform-fmt:
name: Check Terraform Format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.5.7 # Specify your desired Terraform version
- name: Get changed modules
id: changed-modules
uses: tj-actions/changed-files@v35
with:
files: modules/**/*.tf
- name: Run Terraform fmt
run: |
for file in ${{ steps.changed-modules.outputs.all_changed_files }}; do
module_dir=$(dirname "$file")
echo "Running terraform fmt in $module_dir"
terraform fmt -check -recursive -diff "$module_dir"
done
continue-on-error: true
- name: Check Terraform formatting
run: |
if [ ${{ steps.fmt.outcome }} == "failure" ]; then
echo "Terraform files are not properly formatted. Please run 'terraform fmt' to fix."
exit 1
fi
terraform-tflint:
name: Check TFLint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.5.7 # Specify your desired Terraform version
- name: Setup TFLint
uses: terraform-linters/setup-tflint@v3
with:
tflint_version: v0.53.0 # Specify your desired TFLint version
- name: Get changed modules
id: changed-modules
uses: tj-actions/changed-files@v35
with:
files: modules/**/*.tf
- name: Run TFLint
run: |
for file in ${{ steps.changed-modules.outputs.all_changed_files }}; do
module_dir=$(dirname "$file")
if [ ! -f "$module_dir/.tflint.hcl" ]; then
echo "module_dir=$module_dir" >> $GITHUB_OUTPUT
echo "No .tflint.hcl found in $module_dir. Skipping."
continue
fi
echo "Running TFLint in $module_dir"
tflint -f compact "$module_dir"
done