Skip to content

Terraform plugin runs validate on sub-modules, causing false positives #2740

@noahd1

Description

@noahd1

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions