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

Can't use arguments for module inspection #76

Closed
jreisserVeoL opened this issue Nov 18, 2019 · 9 comments
Closed

Can't use arguments for module inspection #76

jreisserVeoL opened this issue Nov 18, 2019 · 9 comments

Comments

@jreisserVeoL
Copy link

Hello!

I'm not sure why but I can't add arguments to terraform_tflint hook. I'm trying to use tflint --module or any argument but I always get the following error message:

getopt: unrecognize option '--module'

Project structures

I'm using official terraform modules which are located in the .terraform file and custom modules.

.
├── .terraform
├── .pre-commit-config.yaml
├── main.tf
├── variables.tf
└── outputs.tf

or

.
├── custom_module
│   ├── main.tf
│   ├── outputs.tf
│   └── variables.tf
│
├── .terraform
├── .pre-commit-config.yaml
├── main.tf
├── outputs.tf
└── variables.tf

pre-commit-config.yaml just contains the following hooks :

- repo: git://github.com/antonbabenko/pre-commit-terraform
  rev: v1.21.0
  hooks:
    - id: terraform_tflint
      args: ['--module']

I use TFLint version 0.13.1, pre-commit 1.20.0 and pre-commit-terraform v1.21.0. pre-commit is up to date.

Is there something I'm missing ? If you have any suggestion or workaround to help us with this problem, I'd greatly appreciate it.

@grzegorzlisowski
Copy link

grzegorzlisowski commented Dec 29, 2019

To make it work you need two things:

  1. Following PR merged into master and new version released (or have your own fork): tflint: iterate over files #77

  2. One of the latest PRs merged to the mainline changed the way of passing arguments to the tflint.

I have no clue how this is working for anyone: https://github.com/antonbabenko/pre-commit-terraform#notes-about-terraform_tflint-hooks

  - id: terraform_tflint
    args: ['--deep']

Maybe I'm missing something important. Per the code in the the script and according to the way how pre-commit passes arguments to the scripts (https://pre-commit.com/#passing-arguments-to-hooks), the only solution which I see is this:

  - id: terraform_tflint
    args: ['--args', '--module']

@djtecha
Copy link

djtecha commented Jan 3, 2020

Yea, this is busted for me too. Tried with a different module just to make sure and it also fails

  hooks:
          #- id: terraform_tflint
          #args: ['--aws-region=us-west-2']     
          #    - id: terraform_fmt
    - id: terraform_docs
      args: ['--dest=TEST.md']
Terraform docs...........................................................Failed
- hook id: terraform_docs
- exit code: 1

getopt: unrecognized option '--dest'

@grzegorzlisowski
Copy link

The story is the same for both terraform_docs and terraform_tflint as they use the same method of sorting out arguments (getopt) which is making handling arguments in specific way.

@matsest
Copy link

matsest commented Jan 21, 2020

Same here with terraform_docs hook, even in the newest version. Not too familiar with pre-commit or getopt, but with adding

    - id: terraform_docs
      args: ['--args=--sort-by-required']

it works. However I can't seem to add more args, and this seems like a very bad workaround.

Any thoughts @antonbabenko?

@Vlaaaaaaad
Copy link

In an interesting twist the following seems work:

    - id: terraform_docs
      args: [--args=--with-aggregate-type-defaults, --args=--no-escape]

@antonbabenko
Copy link
Owner

As @Vlaaaaaaad is saying but enquote values to be like strings. Like this:

    - id: terraform_docs
      args: ["--args=--sort-by-required", "--args=--with-aggregate-type-defaults", "--args=--no-escape"]

@matsest
Copy link

matsest commented Jan 21, 2020

OK, that seems to be working. Would be nice for it to be consistent with other pre-commit hook args (as the README indicates).

@antonbabenko
Copy link
Owner

Agree, we can update README to show the examples for both.

@antonbabenko
Copy link
Owner

v1.25.0 of pre-commit-terraform has been just released after #77 was merged which means that terraform_tflint is usable.

Closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants