-
Notifications
You must be signed in to change notification settings - Fork 267
Terraform plugin runs validate on sub-modules, causing false positives #2740
Description
Summary
The terraform plugin's lint driver runs terraform validate on sub-module directories where it cannot succeed, producing false positive "Missing required provider" errors.
Details
The lint driver is configured with target = { type = "parent" }, so it validates the parent directory of each changed .tf file. When that directory is a sub-module (e.g. terraform/modules/foo/bar/), terraform validate fails because providers aren't installed — terraform init only runs at root module directories.
Root modules (with .terraform/ initialized) validate fine. Sub-modules always fail with:
0:0 high Missing required provider terraform
or:
0:0 high Module not installed terraform
These are not real issues with the Terraform code.
Reproduction
Any repo with Terraform sub-modules that enables the terraform plugin will see false positives when files in module directories are changed. The errors only surface in diff mode when a new module is added or new resources are added to an existing module.
Suggested fix
The lint driver should only run terraform validate on root module directories — those that contain a .terraform.lock.hcl file or a .terraform/ directory. Sub-module directories should be skipped for validation (but can still have terraform fmt applied).
Current workaround
Exclude module directories from the terraform plugin in .qlty/qlty.toml:
[[exclude]]
plugins = ["terraform"]
file_patterns = ["terraform/modules/**"]This also disables terraform fmt on modules, which is a minor tradeoff.