Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sblask opened this issue Oct 6, 2021 · 3 comments · Fixed by #243
Closed

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

sblask opened this issue Oct 6, 2021 · 3 comments · Fixed by #243
Assignees
Labels
area/local_installation bug_with_workaround Something isn't working but there is a workaround estimate/4h Need 4 hours to be done hook/terraform_tflint Bash hook

Comments

@sblask
Copy link

sblask commented Oct 6, 2021

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

  • OS: MacOS Darwin
  • Tools availability and versions:
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
  • .pre-commit-config.yaml:
  - repo: git://github.com/antonbabenko/pre-commit-terraform
    rev: v1.50.0
    hooks:
      - id: terraform_fmt
      - id: terraform_tflint
@sblask sblask added area/local_installation bug Something isn't working labels Oct 6, 2021
@sblask
Copy link
Author

sblask commented Oct 6, 2021

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.

@MaxymVlasov MaxymVlasov added this to the Bug and docs fixes milestone Oct 6, 2021
@MaxymVlasov MaxymVlasov added the estimate/4h Need 4 hours to be done label Oct 6, 2021
@ichiman
Copy link

ichiman commented Oct 8, 2021

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

@MaxymVlasov MaxymVlasov self-assigned this Oct 14, 2021
@MaxymVlasov
Copy link
Collaborator

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

@MaxymVlasov MaxymVlasov added bug_with_workaround Something isn't working but there is a workaround and removed bug Something isn't working labels Oct 14, 2021
@MaxymVlasov MaxymVlasov changed the title terraform_tflint does not find problems that manifest across multiple files v1.52.0 : terraform_tflint provide confusing output like ERROR in ././: Oct 14, 2021
MaxymVlasov added a commit that referenced this issue Oct 14, 2021
If use constructions like:

```bash
HAVE_ERR="$(tflint "${ARGS[@]}" 2>&1)"
if [ ! -z "$HAVE_ERR" ]; then
  echo >&2 -e "\033[1;31m\nERROR in $path_uniq/:\033[0m"
  tflint "${ARGS[@]}"
fi
```

some errors will not printed.

So this one-liner fits our requirements in the best way.

Fixes #240
MaxymVlasov added a commit that referenced this issue Oct 14, 2021
If use constructions like:

```bash
HAVE_ERR="$(tflint "${ARGS[@]}" 2>&1)"
if [ ! -z "$HAVE_ERR" ]; then
  echo >&2 -e "\033[1;31m\nERROR in $path_uniq/:\033[0m"
  tflint "${ARGS[@]}"
fi
```

some errors will not printed.

So this one-liner fits our requirements in the best way.

Fixes #240
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/local_installation bug_with_workaround Something isn't working but there is a workaround estimate/4h Need 4 hours to be done hook/terraform_tflint Bash hook
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants