generated from terraform-linters/tflint-ruleset-template
-
Notifications
You must be signed in to change notification settings - Fork 30
Open
Description
TFLint Version
tflint v0.59.1
Terraform Version
OpenTofu v1.10.6
Description
The terraform_required_providers rule does not recognize provider dependencies under the following conditions:
- Providers are declared with
for_eachandalias - Modules use
for_eachand pass providers via theprovidersblock with dynamic references likekubernetes.kubernetes[each.key]
As a result, TFLint reports missing required_providers entries even though the providers are correctly used:
Failed to check ruleset; failed to check "terraform_required_providers" rule: main.tf:30,18-49: Invalid expression; A single static variable reference is required: only attribute access and indexing with constant keys. No calculations, function calls, template expressions, etc are allowed here., and 1 other diagnostic(s)Example
provider "kubernetes" {
for_each = var.clusters
alias = "kubernetes"
host = "https://${module.kubernetes[each.key].cluster_endpoint}"
cluster_ca_certificate = sensitive(base64decode(module.kubernetes[each.key].cluster_ca_certificate))
token = sensitive(module.kubernetes[each.key].cluster_access_token)
}
module "service_account" {
for_each = module.kubernetes
providers = {
kubernetes = kubernetes.kubernetes[each.key]
}
(...)Expected Behavior
TFLint should detect that the kubernetes provider is used in the module via the providers mapping and not require an explicit required_providers block if the provider is already declared in the root configuration with for_each.
Metadata
Metadata
Assignees
Labels
No labels