antonbabenko / pre-commit-terraform

pre-commit git hooks to take care of Terraform configurations 🇺🇦
MIT License
3.16k stars 535 forks source link

v1.52.0 : `terraform_tflint` provide confusing output like `ERROR in ././:` #240

Closed sblask closed 2 years ago

sblask commented 2 years ago

Describe the bug

tflint has checks like terraform_unused_declarations that can only reasonably be checked across multiple files and terraform_tflint does not find them because it only checks single files.

How can we reproduce it?

Create a directory with two files: variables.tf and main.tf and add to variables.tf:

variable "unused" {
  type = string
}

Also add a tflint.hcl:

plugin "aws" {
  enabled = true
  version = "0.7.2"
  source  = "github.com/terraform-linters/tflint-ruleset-aws"
}

rule "terraform_unused_declarations" {
  enabled = true
}

rule "terraform_comment_syntax" {
  enabled = true
}

rule "terraform_unused_required_providers" {
  enabled = true
}

rule "terraform_naming_convention" {
  enabled = true
}

rule "terraform_typed_variables" {
  enabled = true
}

pre-commit run --all-files will not find a problem. I wrote an own hook that does:

  - repo: local
    hooks:
      - id: tflint
        name: tflint
        entry: bash -c 'tflint --init && echo $@ | xargs dirname | sort --unique | xargs -n1 tflint'
        language: system
        files: \.tf$
        require_serial: true

gives:

Warning: variable "unused" is declared but not used (terraform_unused_declarations)

  on variables.tf line 1:
   1: variable "unused" {

terraform_tflint should give the same warning?

Environment information

pre-commit 2.15.0
Terraform v1.0.8
Python 3.9.7
Python 3.9.7
checkov checkov SKIPPED
terraform-docs version v0.14.1 darwin/amd64
terragrunt SKIPPED
terrascan terrascan SKIPPED
TFLint version 0.31.0
+ ruleset.aws (0.7.2)
tfsec tfsec SKIPPED
  - repo: git://github.com/antonbabenko/pre-commit-terraform
    rev: v1.50.0
    hooks:
      - id: terraform_fmt
      - id: terraform_tflint
sblask commented 2 years ago

Looks like this did work and I got confused with the versions. However, with:

  - repo: git://github.com/antonbabenko/pre-commit-terraform
    rev: v1.52.0
    hooks:
      - id: terraform_fmt
      - id: terraform_tflint

I get:

Terraform validate with tflint...........................................Failed
- hook id: terraform_tflint
- exit code: 3

ERROR in ././:

So the actual message is missing.

ichiman commented 2 years ago

Seeing the same issue with new version. Any ETA when this will be fixed?

MaxymVlasov commented 2 years ago

This works as expected. (for 1.50.0 too)

repos:
  - repo: git://github.com/antonbabenko/pre-commit-terraform
    rev: v1.51.0
    hooks:
      - id: terraform_fmt
      - id: terraform_tflint

Just need to rename tflint.hcl to .tflint.hcl

Confirm ERROR in ././: output in v1.52.0

Workaround

Downgrade to v1.51.0 and wait fix