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

"--recursive" and "--filter" options together not working as expected #1904

Closed
1 of 3 tasks
SharkyND opened this issue Nov 6, 2023 · 2 comments
Closed
1 of 3 tasks

Comments

@SharkyND
Copy link

SharkyND commented Nov 6, 2023

Summary

I'm encountering an issue when using the tflint --recursive --filter='./<somedir>/**' command. It seems that the command is not working as expected, and I'd like to report this as a potential bug.

Steps to reproduce:

  1. Create a couple of folders (i.e tf_test_1, tf_test_2) with terraform code that needs to be linted with tflint.
  2. From the root of that folders run the following command: tflint --recursive --filter='./tf_test_1/**'

Expected behavior:
You should see tflint complaining about the tf code with error that needs to be fixed

Actual behavior:
Don't see any output at all

Additional context:

  • TFLint version: 0.48.
  • Terraform version: v1.5.7
  • Operating system: macOS Ventura - Version 13.6 - ARM64

Please let me know if there's any additional information I can provide or if there's a workaround for this issue. Thank you!

Command

tflint --recursive --filter='./test_tf_1/**'

Terraform Configuration

.
├── test_tf_1
│   └── main.tf
│   └── .tflint.hcl
├── test_tf_2
│   └── main.tf
│   └── .tflint.hcl

Both main.tf can have the same code:

variable "region" {
  type = map(any)
  default = {
    "uk1" = {
      "region" = "uksouth",
    },
    "uk2" = {
      "region" = "ukwest",
    },
    "us" = {
      "region" = "eastus",
    }
    "us2" = {
      "region" = "eastus2",
    }
  }
}

resource "random_password" "password" {
  length           = 16
  special          = true
  override_special = "!#$%&*()-_=+[]{}<>:?"
}

variable "cidr" {
  default = "172.16.0.0/20"
}

TFLint Configuration

plugin "aws" {
    enabled = true
    version = "0.27.0"
    source  = "github.com/terraform-linters/tflint-ruleset-aws"
}
plugin "azurerm" {
    enabled = true
    version = "0.25.1"
    source  = "github.com/terraform-linters/tflint-ruleset-azurerm"
}

Output

<empty>

TFLint Version

0.48.0

Terraform Version

v1.5.7

Operating System

  • Linux
  • macOS
  • Windows
@SharkyND SharkyND added the bug label Nov 6, 2023
@bendrucker bendrucker removed the bug label Nov 6, 2023
@bendrucker
Copy link
Member

Globstar (**) is not supported so that was never going to work:

golang/go#11862

That would be a feature request that we could consider via swapping the glob implementation for one that does.

What works:

tflint --recursive --filter main.tf

Filters are evaluated within the working directory:

tflint/cmd/inspect.go

Lines 35 to 38 in 83655ca

err := cli.withinChangedDir(wd, func() error {
filterFiles := []string{}
for _, pattern := range opts.Filter {
files, err := filepath.Glob(pattern)

So this is working as designed right now, but there is discussion and proposals around implementing additional flags for filtering modules or repurposing the existing filter flag (i.e., break the existing behavior) to allow this.

You're welcome to reopen this as a feature request with more complete background and examples on how it would be used. The given example doesn't show why you wouldn't just use --chdir.

See also:

@SharkyND
Copy link
Author

SharkyND commented Nov 24, 2023

Hi @bendrucker , thanks for your feedback. Here is a feature request for enhancement. It is still up for grooming, please let me know your thoughts on it.

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

No branches or pull requests

2 participants