diff --git a/CI/linters/tflint.yml b/CI/linters/tflint.yml new file mode 100644 index 0000000..e684c8d --- /dev/null +++ b/CI/linters/tflint.yml @@ -0,0 +1,35 @@ +tflint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: terraform-linters/setup-tflint@v4 + with: + tflint_version: v0.55.0 + + - name: Run tflint on Terraform files + run: | + set -euo pipefail + + if ! command -v tflint > /dev/null 2>&1; then + echo "::error::tflint is not installed or not in PATH" + exit 1 + fi + + TF_COUNT=$(find . -type f -name "*.tf" \ + -not -path "./.git/*" \ + -not -path "./.terraform/*" | wc -l | tr -d ' ') + + if [[ "$TF_COUNT" -eq 0 ]]; then + echo "⚠️ No Terraform files found. Skipping." + exit 0 + fi + + tflint --init + + if tflint --recursive; then + echo "✅ tflint passed" + else + echo "❌ tflint found issues" + exit 1 + fi diff --git a/README.md b/README.md index 850ad7f..b168c41 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ that projects compose into their own workflows. | SQLFluff | linters | [CI/linters/sqlfluff.yml](https://github.com/prog-time/workflows/blob/main/CI/linters/sqlfluff.yml) | | Stylelint | linters | [CI/linters/stylelint.yml](https://github.com/prog-time/workflows/blob/main/CI/linters/stylelint.yml) | | SwiftLint | linters | [CI/linters/swiftlint.yml](https://github.com/prog-time/workflows/blob/main/CI/linters/swiftlint.yml) | +| tflint | linters | [CI/linters/tflint.yml](https://github.com/prog-time/workflows/blob/main/CI/linters/tflint.yml) | | yamllint | linters | [CI/linters/yamllint.yml](https://github.com/prog-time/workflows/blob/main/CI/linters/yamllint.yml) | | mypy | static_analysis | [CI/static_analysis/mypy.yml](https://github.com/prog-time/workflows/blob/main/CI/static_analysis/mypy.yml) | | 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/ │ │ │ ├── sqlfluff.yml │ │ │ ├── stylelint.yml │ │ │ ├── swiftlint.yml +│ │ │ ├── tflint.yml │ │ │ └── yamllint.yml │ │ ├── security/ │ │ │ ├── gitleaks.yml @@ -120,6 +122,7 @@ Workflows/ │ │ ├── sqlfluff.sh │ │ ├── stylelint.sh │ │ ├── swiftlint.sh +│ │ ├── tflint.sh │ │ └── yamllint.sh │ ├── security/ │ │ ├── gitleaks.sh @@ -145,6 +148,7 @@ Workflows/ │ │ ├── shellcheck.bats │ │ ├── sqlfluff.bats │ │ ├── stylelint.bats +│ │ ├── tflint.bats │ │ └── yamllint.bats │ ├── security/ │ │ ├── gitleaks.bats @@ -247,6 +251,7 @@ shellcheck: | `CI/linters/sqlfluff.yml` | [sqlfluff](https://sqlfluff.com) | SQL files | | `CI/linters/stylelint.yml` | [stylelint](https://stylelint.io) | CSS / SCSS / LESS | | `CI/linters/swiftlint.yml` | [swiftlint](https://realm.github.io/SwiftLint) | Swift | +| `CI/linters/tflint.yml` | [tflint](https://github.com/terraform-linters/tflint) | Terraform | | `CI/linters/yamllint.yml` | [yamllint](https://yamllint.readthedocs.io) | YAML files | ### Static analysis diff --git a/scripts/CI/linters/tflint.yml b/scripts/CI/linters/tflint.yml new file mode 100644 index 0000000..a3c5683 --- /dev/null +++ b/scripts/CI/linters/tflint.yml @@ -0,0 +1,11 @@ +tflint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: terraform-linters/setup-tflint@v4 + with: + tflint_version: v0.55.0 + + - name: Run tflint on Terraform files + run: bash scripts/shell/linters/tflint.sh diff --git a/scripts/shell/linters/tflint.sh b/scripts/shell/linters/tflint.sh new file mode 100644 index 0000000..3fe815a --- /dev/null +++ b/scripts/shell/linters/tflint.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +set -euo pipefail + +if ! command -v tflint > /dev/null 2>&1; then + echo "::error::tflint is not installed or not in PATH" + exit 1 +fi + +TF_COUNT=$(find . -type f -name "*.tf" \ + -not -path "./.git/*" \ + -not -path "./.terraform/*" | wc -l | tr -d ' ') + +if [[ "$TF_COUNT" -eq 0 ]]; then + echo "⚠️ No Terraform files found. Skipping." + exit 0 +fi + +tflint --init + +if tflint --recursive; then + echo "✅ tflint passed" +else + echo "❌ tflint found issues" + exit 1 +fi diff --git a/tests/linters/tflint.bats b/tests/linters/tflint.bats new file mode 100644 index 0000000..6919085 --- /dev/null +++ b/tests/linters/tflint.bats @@ -0,0 +1,53 @@ +#!/usr/bin/env bats + +load "../helpers/common" + +SCRIPT="$BATS_TEST_DIRNAME/../../scripts/shell/linters/tflint.sh" + +setup() { + setup_test_dir + mkdir -p "$TEST_DIR/bin" + export PATH="$TEST_DIR/bin:$PATH" +} + +teardown() { + teardown_test_dir +} + +make_tflint_stub() { + local exit_code="$1" + cat > "$TEST_DIR/bin/tflint" <