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

[3rd party: tflint] terraform_tflint.sh still throws "command not found" #270

Closed
shoof1072 opened this issue Oct 26, 2021 · 1 comment
Closed
Labels
3rd party Issues not related to `pre-commit-terraform` hook/terraform_tflint Bash hook

Comments

@shoof1072
Copy link

terraform_tflint.sh still throws "command not found"

Expected: This behavior was expected to be fixed by PR #251
Observed: When intentionally changing a terraform file to cause a linting failure observed the following

$ pre-commit
Terraform fmt............................................................Passed
Terraform validate with tflint...........................................Failed
- hook id: terraform_tflint
- exit code: 127


ERROR in terraform/:
$HOME/.cache/pre-commit/repohu82fesd/terraform_tflint.sh: line 70: tflint: command not found

How can we reproduce it?

Well, interestingly this error is observed even when there is a formatting error detected by terraform_fmt.

The relevant section of the .pre-commit-config.yaml used when trying to add terraform_tflint is:

repos:
  - repo: https://github.com/antonbabenko/pre-commit-terraform
    rev: e33c654a4005cff364a42f965068160e4ba3e3c2  
    hooks:
      - id: terraform_fmt
      - id: terraform_tflint

So, for example, if I have the following terraform:

resource "aws_iam_role_policy" "some_iam_policy" {
  count  = my_count
  policy = my_policy_document
  role   = arbitrary_role
}

And I change the formatting to cause terraform_fmt to catch and reformat due to expressions no longer aligning on the equals operator, ex:

resource "aws_iam_role_policy" "some_iam_policy" {
  count  = my_count
  policy = my_policy_document
  role = arbitrary_role
}

Then the observed behavior is that terraform_fmt will catch and fix the formatting error, but the terraform_tflint.sh script will will return "file not found".

If I intentionally cause a linting error, for example changing the keyword source in a module to source_

module "my_module" {
  source_ = "git::ssh:/git@some_url"
  ...
  ...
}     

The same error is observed:

ERROR in terraform/:
$HOME/.cache/pre-commit/repohu82fesd/terraform_tflint.sh: line 70: tflint: command not found

Environment information

  • OS: Ubuntu 21.10
  • uname -a and/or systeminfo | Select-String "^OS" output:
$ uname -a
Linux shoofcrash01 5.13.0-20-generic #20-Ubuntu SMP Fri Oct 15 14:21:35 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
  • Tools availability and versions:
pre-commit 2.10.1
Terraform v1.0.8
Python 3.8.2
Python 3.8.2
checkov checkov SKIPPED
terraform-docs SKIPPED
terragrunt SKIPPED
terrascan terrascan SKIPPED
tflint SKIPPED
tfsec tfsec SKIPPED
  • .pre-commit-config.yaml:
file content
default_language_version:
  python: python3.8
repos:
  - repo: https://github.com/antonbabenko/pre-commit-terraform
    rev: e33c654a4005cff364a42f965068160e4ba3e3c2  # frozen: v1.52.0
    hooks:
      - id: terraform_fmt
      - id: terraform_tflint
        args:
          - --args=--loglevel=debug
          - --args=--deep
          - --args=--module # module inspection won't run without terraform --init
          - --args=--enable-rule=terraform_documented_outputs
          - --args=--enable-rule=terraform_documented_variables
          - --args=--enable-rule=terraform_standard_module_structure
@shoof1072 shoof1072 added area/local_installation bug Something isn't working labels Oct 26, 2021
@shoof1072
Copy link
Author

Ahh, looks like dependencies indicated TFLint is required for the terraform_tflint hook. After install of TFLint the "command not found" is no longer observed.

Closing.

@MaxymVlasov MaxymVlasov added 3rd party Issues not related to `pre-commit-terraform` hook/terraform_tflint Bash hook and removed bug Something isn't working area/local_installation labels Nov 5, 2021
@MaxymVlasov MaxymVlasov changed the title terraform_tflint.sh still throws "command not found" [3rd party: tflint] terraform_tflint.sh still throws "command not found" Nov 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3rd party Issues not related to `pre-commit-terraform` hook/terraform_tflint Bash hook
Projects
None yet
Development

No branches or pull requests

2 participants