Skip to content

Commit 4c77ccf

Browse files
authored
Introduce tflint (#30)
1 parent dd9d222 commit 4c77ccf

File tree

5 files changed

+252
-102
lines changed

5 files changed

+252
-102
lines changed

.github/workflows/integration.yaml

-101
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: Integration (Terraform)
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request: {}
8+
9+
concurrency:
10+
group: terraform-integration-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
changed:
15+
name: Filter Changed Files and Directories
16+
runs-on: ubuntu-latest
17+
18+
outputs:
19+
changed: ${{ steps.set-outputs.outputs.changed }}
20+
modified: ${{ steps.set-outputs.outputs.modified }}
21+
changed_files: ${{ steps.set-outputs.outputs.changed_files }}
22+
modified_files: ${{ steps.set-outputs.outputs.modified_files }}
23+
changed_directories: ${{ steps.set-outputs.outputs.changed_directories }}
24+
modified_directories: ${{ steps.set-outputs.outputs.modified_directories }}
25+
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v3
29+
with:
30+
fetch-depth: 0
31+
32+
- name: Get Changed Files
33+
id: changed-files
34+
uses: tj-actions/changed-files@v35
35+
with:
36+
files: |
37+
modules/**
38+
json: true
39+
40+
- name: Get Changed Directories
41+
id: changed-directories
42+
uses: tj-actions/changed-files@v35
43+
with:
44+
files: |
45+
modules/**
46+
examples/**
47+
dir_names: "true"
48+
dir_names_max_depth: 2
49+
json: true
50+
51+
- name: Set outputs
52+
id: set-outputs
53+
run: |
54+
echo "changed=${{ steps.changed-directories.outputs.any_changed }}" >> $GITHUB_OUTPUT
55+
echo "modified=${{ steps.changed-directories.outputs.any_modified }}" >> $GITHUB_OUTPUT
56+
57+
echo "changed_files=${{ steps.changed-files.outputs.all_changed_files }}" >> $GITHUB_OUTPUT
58+
echo "modified_files=${{ steps.changed-files.outputs.all_modified_files }}" >> $GITHUB_OUTPUT
59+
60+
echo "changed_directories=${{ steps.changed-directories.outputs.all_changed_files }}" >> $GITHUB_OUTPUT
61+
echo "modified_directories=${{ steps.changed-directories.outputs.all_modified_files }}" >> $GITHUB_OUTPUT
62+
63+
64+
terraform:
65+
name: Lint (terraform)
66+
needs:
67+
- changed
68+
if: ${{ needs.changed.outputs.modified == 'true' }}
69+
uses: tedilabs/.github/.github/workflows/terraform.terraform.yaml@main
70+
71+
strategy:
72+
matrix:
73+
path: ${{ fromJson(needs.changed.outputs.modified_directories) }}
74+
75+
with:
76+
terraform_target_dir: ${{ matrix.path }}
77+
terraform_version: latest
78+
terraform_host: app.terraform.io
79+
secrets:
80+
terraform_token: ${{ secrets.TERRAFORM_TOKEN }}
81+
82+
83+
tflint:
84+
name: Lint (tflint)
85+
needs:
86+
- changed
87+
if: ${{ needs.changed.outputs.modified == 'true' }}
88+
uses: tedilabs/.github/.github/workflows/terraform.tflint.yaml@main
89+
90+
strategy:
91+
matrix:
92+
path: ${{ fromJson(needs.changed.outputs.modified_directories) }}
93+
94+
with:
95+
tflint_version: latest
96+
tflint_config_file: .tflint.hcl
97+
tflint_target_dir: ${{ matrix.path }}
98+
tflint_recursive_enabled: false
99+
tflint_terraform_init_enabled: true
100+
terraform_version: latest
101+
terraform_host: app.terraform.io
102+
secrets:
103+
token: ${{ secrets.GITHUB_TOKEN }}
104+
terraform_token: ${{ secrets.TERRAFORM_TOKEN }}
+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Integration (YAML)
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request: {}
8+
9+
concurrency:
10+
group: yaml-integration-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
changed:
15+
name: Filter Changed Files and Directories
16+
runs-on: ubuntu-latest
17+
18+
outputs:
19+
changed: ${{ steps.set-outputs.outputs.changed }}
20+
modified: ${{ steps.set-outputs.outputs.modified }}
21+
changed_files: ${{ steps.set-outputs.outputs.changed_files }}
22+
modified_files: ${{ steps.set-outputs.outputs.modified_files }}
23+
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v3
27+
with:
28+
fetch-depth: 0
29+
30+
- name: Get Changed Files
31+
id: changed-files
32+
uses: tj-actions/changed-files@v35
33+
with:
34+
files: |
35+
**/*.yaml
36+
**/*.yml
37+
json: true
38+
39+
- name: Set outputs
40+
id: set-outputs
41+
run: |
42+
echo "changed=${{ steps.changed-files.outputs.any_changed }}" >> $GITHUB_OUTPUT
43+
echo "modified=${{ steps.changed-files.outputs.any_modified }}" >> $GITHUB_OUTPUT
44+
45+
echo "changed_files=${{ steps.changed-files.outputs.all_changed_files }}" >> $GITHUB_OUTPUT
46+
echo "modified_files=${{ steps.changed-files.outputs.all_modified_files }}" >> $GITHUB_OUTPUT
47+
48+
lint:
49+
name: Lint (yamllint)
50+
needs:
51+
- changed
52+
if: ${{ needs.changed.outputs.modified == 'true' }}
53+
uses: tedilabs/.github/.github/workflows/yaml.yamllint.yaml@main
54+
55+
with:
56+
yamllint_version: latest
57+
yamllint_config_file: .yamllint.yaml
58+
yamllint_target_dir: ./

.pre-commit-config.yaml

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
repos:
22
- repo: https://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.70.1
3+
rev: v1.77.1
44
hooks:
55
- id: terraform_fmt
6+
args:
7+
- --args=-diff
68
- id: terraform_validate
9+
args:
10+
- --hook-config=--retry-once-with-cleanup=true
11+
- id: terraform_tflint
12+
args:
13+
- --args=--config=__GIT_WORKING_DIR__/.tflint.hcl
14+
files: ^modules/
715
- id: terraform_docs
816
args: ["--args=--sort-by required"]
17+
- repo: https://github.com/adrienverge/yamllint
18+
rev: v1.29.0
19+
hooks:
20+
- id: yamllint

.tflint.hcl

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
config {
2+
plugin_dir = "~/.tflint.d/plugins"
3+
4+
format = "compact"
5+
module = true
6+
force = false
7+
disabled_by_default = false
8+
9+
ignore_module = {}
10+
}
11+
12+
13+
###################################################
14+
# Rule Sets - Terraform
15+
###################################################
16+
17+
plugin "terraform" {
18+
enabled = true
19+
preset = "recommended"
20+
}
21+
22+
rule "terraform_comment_syntax" {
23+
enabled = true
24+
}
25+
26+
rule "terraform_documented_variables" {
27+
enabled = true
28+
}
29+
30+
rule "terraform_documented_outputs" {
31+
enabled = true
32+
}
33+
34+
rule "terraform_naming_convention" {
35+
enabled = true
36+
format = "snake_case"
37+
38+
custom_formats = {
39+
extended_snake_case = {
40+
description = "Extended snake_case Format which allows double underscore like `a__b`."
41+
regex = "^[a-z][a-z0-9]+([_]{1,2}[a-z0-9]+)*$"
42+
}
43+
}
44+
45+
module {
46+
format = "extended_snake_case"
47+
}
48+
49+
resource {
50+
format = "extended_snake_case"
51+
}
52+
53+
data {
54+
format = "extended_snake_case"
55+
}
56+
}
57+
58+
rule "terraform_unused_declarations" {
59+
enabled = false
60+
}
61+
62+
rule "terraform_unused_required_providers" {
63+
enabled = true
64+
}
65+
66+
67+
###################################################
68+
# Rule Sets - AWS
69+
###################################################
70+
71+
plugin "aws" {
72+
source = "github.com/terraform-linters/tflint-ruleset-aws"
73+
version = "0.21.1"
74+
75+
enabled = true
76+
deep_check = false
77+
}

0 commit comments

Comments
 (0)