Closed tofupup closed 2 years ago
Agreed that this behavior is not intuitive. As you say, the --only
option should take precedence over other configs.
However, this seems difficult to fix quickly for internal reasons. The config should be evaluated with the following priority:
--only
(CLI flag)--enable-rule
, --disable-rule
(CLI flag)rule
block (config file)preset
(config file)disabled_by_default
(config file)Internally, 1 and 5 are the same representation and the plugin cannot distinguish between them. The current behavior is that the --only
option is identified as 5, so the config file takes precedence. I think we probably need to be able to send the --only
option as another representation to the plugin and interpret it.
As a workaround, I recommend explicitly setting disabled_by_default
in your .tflint.hcl
file instead of using the --only
option.
@wata727 maybe I'm missing something but proposed workaround is not working for me
$ cat <<EOS > .tflint.test.hcl
config {
disabled_by_default = true
}
rule "terraform_naming_convention" {
enabled = true
}
EOS
$ mkdir work
$ cat <<EOS > work/main.tf
resource "aws_instance" "main-main" {
instance_type = "tx.micro"
}
EOS
$ tree work
work
├── main.tf
0 directory, 1 file
$ tflint -c .tflint.test.hcl ./work/
2 issue(s) found:
Warning: terraform "required_version" attribute is required (terraform_required_version)
on line 0:
(source code not available)
Reference: https://github.com/terraform-linters/tflint-ruleset-terraform/blob/v0.1.0/docs/rules/terraform_required_version.md
Warning: Missing version constraint for provider "aws" in "required_providers" (terraform_required_providers)
on work/main.tf line 1:
1: resource "aws_instance" "main" {
Reference: https://github.com/terraform-linters/tflint-ruleset-terraform/blob/v0.1.0/docs/rules/terraform_required_providers.md
It seems to be a bug that occurs because the "recommended" preset is applied by default. Try declaring the terraform
plugin block:
plugin "terraform" {
enabled = true
}
Introduction
Running
tflint
0.40.0 seems to ignore--only=<rule>
options on the CLI. My interpretation of the 0.40.0 changelog and the User Guide is that--only
names will override other enable/disabled rule declarations. However, it appears the defaultpreset = "recommended"
takes precedence on what gets run. If a~/.tflint.hcl
is created withpreset = "all"
, tests that are not included in--only
are still run, so there doesn't seem to be a way to run non-recommended rules without specifying it specifically in a configuration file.Can you clarify if this is intended behavior now?
Running with
tflint
0.39.3 without~/.tflint.hcl
:Running with
tflint
0.40.0 without~/.tflint.hcl
:Running with
tflint
0.40.0 with~/.tflint.hcl
withpreset ="recommended" and
--only=terraform_naming_convention` removed from CLI:Running with
tflint
0.40.0 with~/.tflint.hcl
withpreset ="all"
and--only=terraform_naming_convention
removed from CLI:Expected Behavior
I expected that
--only
options would override which rules were run, or at least complement the rules set by the.tflint.hcl
file.Actual behavior
It appears the settings in the
.tflint.hcl
file override the--only=
CLI options.Step to Reproduce
Using the simple
main.tf
code provided in the Introduction, the example commands provided above should reproduce what I'm seeing.main.tf
:Commands above in Introduction as well, let me know if you need more information (or if I'm using things wrong!)
Additional Context