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

standard_module_structure: fix false positives when passing a directory #859

Merged
merged 2 commits into from
Jul 31, 2020

Conversation

bendrucker
Copy link
Member

@bendrucker bendrucker commented Jul 30, 2020

As reported in #834, the terraform_standard_module_structure was reporting false warnings when TFLint was invoked with a non-cwd directory:

$ /usr/local/bin/tflint -c /tmp/.tflint.hcl /tmp/ok
2 issue(s) found:

Warning: output "test" should be moved from /tmp/ok/outputs.tf to outputs.tf (terraform_standard_module_structure)

  on /tmp/ok/outputs.tf line 1:
   2: output "test" {

Reference: https://github.com/terraform-linters/tflint/blob/v0.17.0/docs/rules/terraform_standard_module_structure.md

Warning: variable "test" should be moved from /tmp/ok/variables.tf to variables.tf (terraform_standard_module_structure)

  on /tmp/ok/variables.tf line 1:
   1: variable "test" {

Reference: https://github.com/terraform-linters/tflint/blob/v0.17.0/docs/rules/terraform_standard_module_structure.md

Directories were properly handled when checking that the required files were present:

files := runner.Files()
for name, file := range files {
files[filepath.Base(name)] = file
}

The logic that checked parsed variables/outputs for their filenames was missing that same logic.

Before including the fix, the modified test validates the bug, failing because of an unexpected issue:

--- FAIL: Test_TerraformStandardModuleStructureRule (0.00s)
    --- FAIL: Test_TerraformStandardModuleStructureRule/directory_in_path (0.00s)
        testing.go:83: Expected issues are not matched:
               tflint.Issues{
              	&{Rule: &terraformrules.TerraformStandardModuleStructureRule{}, Message: "Module should include an empty outputs.tf file", Range: {Filename: "foo/outputs.tf", Start: {Line: 1, Column: 1}}},
            + 	&{
            + 		Rule:    &terraformrules.TerraformStandardModuleStructureRule{},
            + 		Message: `variable "v" should be moved from foo/variables.tf to variables.tf`,
            + 		Range:   s"foo/variables.tf:2,1-13",
            + 	},
              }
            
FAIL
FAIL	github.com/terraform-linters/tflint/rules/terraformrules	0.391s
FAIL

Closes #834

@bendrucker bendrucker merged commit 0ef6718 into master Jul 31, 2020
@bendrucker bendrucker deleted the standard-module-dir branch July 31, 2020 01:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

rule terraform_standard_module_structure throws false warnings
1 participant