terraform-linters / tflint

A Pluggable Terraform Linter
Mozilla Public License 2.0
4.86k stars 353 forks source link

`--recursive $DIR` doesn't work but `--recursive .` does #1649

Closed chb0github closed 1 year ago

chb0github commented 1 year ago

Summary

I am trying to recusrively scan a directory by name, which should be:

tflint --recursive $dirname and I get an error. But when I go into that same directory and add . as the directory, it's fine

cbongior@soho-cbongio-l1:/mnt/c/Users/cbongior/dev/wr$ docker run -it -w /root -v $PWD:/root --entrypoint=sh ghcr.io/terraform-linters/tflint-bundle
~ # ls
 wr-studio-installer   
~ # tflint --recursive wr-studio-installer
Cannot use --recursive and arguments at the same time
~ # cd wr-studio-installer/
~/wr-studio-installer # tflint --recursive .
...
Warning: variable "image_tag" is declared but not used (terraform_unused_declarations)

  on modules/tools/modules/wrsc/variables.tf line 33:
  33: variable "image_tag" {

Reference: https://github.com/terraform-linters/tflint-ruleset-terraform/blob/v0.2.2/docs/rules/terraform_unused_declarations.md

This is being run in ubuntu on WSL V2

Command

tflint --recusrive .

Terraform Configuration

doesn't apply

TFLint Configuration

using docker container:
ghcr.io/terraform-linters/tflint-bundle

Output

~ # tflint --recursive wr-studio-installer
Cannot use --recursive and arguments at the same time

TFLint Version

0.44.1

Terraform Version

No response

Operating System

bendrucker commented 1 year ago

Have you tried this with --chdir? Passing modules as arguments is deprecated and will be removed in an upcoming version.

taoufik07 commented 1 year ago

Have you tried this with --chdir? Passing modules as arguments is deprecated and will be removed in an upcoming version.

The cli warns and exit when passing both --chdir and --recursive, though the fix seems pretty simple, I can make a PR if needed, unless there are some hidden snakes in the jar -- probably @wata727 could give us more insights.

wata727 commented 1 year ago

First, the --recursive . works correctly is not the intended behavior. An error should be raised for all directory arguments, even if it is the current directory.

On the other hand, I'm wondering if --recursive and --chdir should be allowed at the same time. Internally --recursive is an alias for --chdir to each directory and is not supposed to be used at the same time.

Probably, you want to limit the directories that are recursively inspected, but I'm not sure that's what --chdir should do.