File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ tflint :
2+ runs-on : ubuntu-latest
3+ steps :
4+ - uses : actions/checkout@v4
5+
6+ - uses : terraform-linters/setup-tflint@v4
7+ with :
8+ tflint_version : v0.55.0
9+
10+ - name : Run tflint on Terraform files
11+ run : |
12+ set -euo pipefail
13+
14+ if ! command -v tflint > /dev/null 2>&1; then
15+ echo "::error::tflint is not installed or not in PATH"
16+ exit 1
17+ fi
18+
19+ TF_COUNT=$(find . -type f -name "*.tf" \
20+ -not -path "./.git/*" \
21+ -not -path "./.terraform/*" | wc -l | tr -d ' ')
22+
23+ if [[ "$TF_COUNT" -eq 0 ]]; then
24+ echo "⚠️ No Terraform files found. Skipping."
25+ exit 0
26+ fi
27+
28+ tflint --init
29+
30+ if tflint --recursive; then
31+ echo "✅ tflint passed"
32+ else
33+ echo "❌ tflint found issues"
34+ exit 1
35+ fi
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ that projects compose into their own workflows.
2727| SQLFluff | linters | [ CI/linters/sqlfluff.yml] ( https://github.com/prog-time/workflows/blob/main/CI/linters/sqlfluff.yml ) |
2828| Stylelint | linters | [ CI/linters/stylelint.yml] ( https://github.com/prog-time/workflows/blob/main/CI/linters/stylelint.yml ) |
2929| SwiftLint | linters | [ CI/linters/swiftlint.yml] ( https://github.com/prog-time/workflows/blob/main/CI/linters/swiftlint.yml ) |
30+ | tflint | linters | [ CI/linters/tflint.yml] ( https://github.com/prog-time/workflows/blob/main/CI/linters/tflint.yml ) |
3031| yamllint | linters | [ CI/linters/yamllint.yml] ( https://github.com/prog-time/workflows/blob/main/CI/linters/yamllint.yml ) |
3132| mypy | static_analysis | [ CI/static_analysis/mypy.yml] ( https://github.com/prog-time/workflows/blob/main/CI/static_analysis/mypy.yml ) |
3233| PHPStan | static_analysis | [ CI/static_analysis/phpstan.yml] ( https://github.com/prog-time/workflows/blob/main/CI/static_analysis/phpstan.yml ) |
@@ -87,6 +88,7 @@ Workflows/
8788│ │ │ ├── sqlfluff.yml
8889│ │ │ ├── stylelint.yml
8990│ │ │ ├── swiftlint.yml
91+ │ │ │ ├── tflint.yml
9092│ │ │ └── yamllint.yml
9193│ │ ├── security/
9294│ │ │ ├── gitleaks.yml
@@ -120,6 +122,7 @@ Workflows/
120122│ │ ├── sqlfluff.sh
121123│ │ ├── stylelint.sh
122124│ │ ├── swiftlint.sh
125+ │ │ ├── tflint.sh
123126│ │ └── yamllint.sh
124127│ ├── security/
125128│ │ ├── gitleaks.sh
@@ -145,6 +148,7 @@ Workflows/
145148│ │ ├── shellcheck.bats
146149│ │ ├── sqlfluff.bats
147150│ │ ├── stylelint.bats
151+ │ │ ├── tflint.bats
148152│ │ └── yamllint.bats
149153│ ├── security/
150154│ │ ├── gitleaks.bats
@@ -247,6 +251,7 @@ shellcheck:
247251| `CI/linters/sqlfluff.yml` | [sqlfluff](https://sqlfluff.com) | SQL files |
248252| `CI/linters/stylelint.yml` | [stylelint](https://stylelint.io) | CSS / SCSS / LESS |
249253| `CI/linters/swiftlint.yml` | [swiftlint](https://realm.github.io/SwiftLint) | Swift |
254+ | `CI/linters/tflint.yml` | [tflint](https://github.com/terraform-linters/tflint) | Terraform |
250255| `CI/linters/yamllint.yml` | [yamllint](https://yamllint.readthedocs.io) | YAML files |
251256
252257# ## Static analysis
Original file line number Diff line number Diff line change 1+ tflint :
2+ runs-on : ubuntu-latest
3+ steps :
4+ - uses : actions/checkout@v4
5+
6+ - uses : terraform-linters/setup-tflint@v4
7+ with :
8+ tflint_version : v0.55.0
9+
10+ - name : Run tflint on Terraform files
11+ run : bash scripts/shell/linters/tflint.sh
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ set -euo pipefail
3+
4+ if ! command -v tflint > /dev/null 2>&1 ; then
5+ echo " ::error::tflint is not installed or not in PATH"
6+ exit 1
7+ fi
8+
9+ TF_COUNT=$( find . -type f -name " *.tf" \
10+ -not -path " ./.git/*" \
11+ -not -path " ./.terraform/*" | wc -l | tr -d ' ' )
12+
13+ if [[ " $TF_COUNT " -eq 0 ]]; then
14+ echo " ⚠️ No Terraform files found. Skipping."
15+ exit 0
16+ fi
17+
18+ tflint --init
19+
20+ if tflint --recursive; then
21+ echo " ✅ tflint passed"
22+ else
23+ echo " ❌ tflint found issues"
24+ exit 1
25+ fi
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bats
2+
3+ load " ../helpers/common"
4+
5+ SCRIPT=" $BATS_TEST_DIRNAME /../../scripts/shell/linters/tflint.sh"
6+
7+ setup () {
8+ setup_test_dir
9+ mkdir -p " $TEST_DIR /bin"
10+ export PATH=" $TEST_DIR /bin:$PATH "
11+ }
12+
13+ teardown () {
14+ teardown_test_dir
15+ }
16+
17+ make_tflint_stub () {
18+ local exit_code=" $1 "
19+ cat > " $TEST_DIR /bin/tflint" << EOF
20+ #!/usr/bin/env bash
21+ # --init always succeeds; --recursive exits with the configured code
22+ for arg in "\$ @"; do
23+ if [[ "\$ arg" == "--recursive" ]]; then
24+ exit $exit_code
25+ fi
26+ done
27+ exit 0
28+ EOF
29+ chmod +x " $TEST_DIR /bin/tflint"
30+ }
31+
32+ @test " no Terraform files: exits 0 with skip message" {
33+ make_tflint_stub 0
34+ run bash " $SCRIPT "
35+ [ " $status " -eq 0 ]
36+ [[ " $output " == * " ⚠️ No Terraform files found. Skipping." * ]]
37+ }
38+
39+ @test " Terraform files present, tflint passes: exits 0 with success message" {
40+ make_tflint_stub 0
41+ touch main.tf
42+ run bash " $SCRIPT "
43+ [ " $status " -eq 0 ]
44+ [[ " $output " == * " ✅ tflint passed" * ]]
45+ }
46+
47+ @test " Terraform files present, tflint finds issues: exits 1 with failure message" {
48+ make_tflint_stub 1
49+ touch main.tf
50+ run bash " $SCRIPT "
51+ [ " $status " -eq 1 ]
52+ [[ " $output " == * " ❌ tflint found issues" * ]]
53+ }
You can’t perform that action at this time.
0 commit comments