Closed brycelowe closed 10 months ago
We are encountering this issue as well, where the .tflint
file in the root of a project used to be read in and used by pre-commit for files in subfolders, but now that config is ignored.
We confirmed that moving the base .tflint
file into any affected project subfolder remedied the issue for files in that specific folder. Not a solution, per se, but another data point that chdir
is at work here.
Experiencing the same issue as @brycelowe .
Hope this gets fixed soon as we cannot keep copying .tflint.hcl
into so many subdirectories.
I proposed a fix but I haven't heard anything on my PR.
Describe the bug We utilize a monorepo for our terraform configurations and we have integrated into our CI pipline precommit checks with the tflint precommit plugin. What I've noticed is that ever since the release of chdir my
.tflint.hcl
file is no longer effective. It looks like because tflint is actually changing the current working directory (https://github.com/terraform-linters/tflint/blob/0e58cd19e334b6c1edfc4ba6d9f4778a28a3342e/cmd/inspect.go#L35C20-L35C20 and https://github.com/terraform-linters/tflint/blob/0e58cd19e334b6c1edfc4ba6d9f4778a28a3342e/cmd/cli.go#L178) and then loading the config file (https://github.com/terraform-linters/tflint/blob/0e58cd19e334b6c1edfc4ba6d9f4778a28a3342e/cmd/inspect.go#L110). The result is tflint failing on rules that I've called out as disabled in my base .tflint.hcl file.To Reproduce
Expected behavior I'd expect the .tflint.hcl file to be honored from the repo root directory like it used to, but the functionality of tflint has changed.
Nice to have
cat < .pre-commit-config.yaml
repos:
cat < .tflint.hcl
rule "terraform_required_providers" {
enabled = false
}
EOF
pushd module >/dev/null
cat < main.tf
resource "null_resource" "foo" {
triggers = {
"coffee" = "sandwich"
}
}
EOF
popd >/dev/null
git add . pre-commit install pre-commit run tflint-demo tflint-demo/module Initialized empty Git repository in /Users/blowe/project-scratch-space/tflint-demo/.git/ pre-commit installed at .git/hooks/pre-commit Terragrunt hclfmt........................................................Passed tflint...................................................................Failed
1 issue(s) found:
Warning: Missing version constraint for provider "null" in
required_providers
(terraform_required_providers)on module/main.tf line 1: 1: resource "null_resource" "foo" {
Reference: https://github.com/terraform-linters/tflint-ruleset-terraform/blob/v0.4.0/docs/rules/terraform_required_providers.md