terraform-linters / tflint

A Pluggable Terraform Linter
Mozilla Public License 2.0
4.73k stars 349 forks source link

cmd: Allow `--chdir` and `--recursive` to be used together #2079

Open wata727 opened 2 days ago

wata727 commented 2 days ago

Fixes https://github.com/terraform-linters/tflint/issues/2051

Previously, --chdir and --recursive could not be used together.

$ tflint --chdir=infra --recursive
Failed to find workspaces; cannot use --recursive and --chdir at the same time

This is because the --recursive was originally designed as --chdir for multi-directory https://github.com/terraform-linters/tflint/pull/1612 https://github.com/terraform-linters/tflint/pull/1622 Given this background, using them together was out of scope. Also, it is not obvious whether --recursive or --chdir takes precedence, which can lead to strange behavior when --recursive takes precedence.

However, given that terraform -chdir=infra fmt --recursive is a valid command, it is natural to expect similar behavior. In terraform fmt, -chdir takes precedence and recurses into the directory after the move. TFLint follows this behavior.