terraform_unused_required_providers
: check child modules for required_providers
#1477
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently,
terraform_unused_required_providers
has a tricky bug that conflicts with official module development recommendations, as detailed in terraform-linters/tflint-ruleset-terraform#21. This is a hacky fix, which, when built, correctly detects that a child module declares the required provider and that the parent is setting a more specific requirement. I'm putting this up for discussion around creating the supporting APIs so that terraform-linters/tflint-ruleset-terraform#21 can be solved without resorting to hacks.Issues include:
NewModuleRunners
, which a plugin using the SDK would be unable to do. More generally, rules right now are expected to evaluate a single module and broadcast issues up, not inspect children directly.NewModuleRunners
returns empty when the modules aren't loaded so perhapslen(moduleRunners) == 0 && len(moduleBlocks) > 0
is enough to indicate that module mode could have but wasn't used. This rule, if it's going to attempt to detect required providers in child modules, should presumably include a warning when those modules are unavailable.TestRunner
expects all files to be in the same dir, and we'd probably want to add a separate method for testing configs across multiple modules.