Closed jkinkead closed 1 year ago
Agreed, the error message is a bit confusing, but I think this comes down to the legacy required_providers
specification:
In a literal sense there is a declaration for an aws
provider, Terraform is just not considering it. This example helps highlight why:
main.tf
terraform {
required_providers {
null = {
source = "hashicorp/null"
}
}
}
provider "null" {}
module "m" {
source = "./module"
providers = {
null = null
}
}
module/main.tf
terraform {
required_providers {
null = {
# a random fork
source = "hc-doc-sparkle/null"
}
}
}
resource "null_resouce" "this" {}
This configuration produces an error on terraform init
:
╷
│ Error: Provider type mismatch
│
│ on main.tf line 15, in module "m":
│ 15: null = null
│
│ The local name "null" in the root module represents provider "hashicorp/null", but "null" in module.m represents "hc-doc-sparkle/null".
│
│ Each provider has its own distinct configuration schema and provider types, so this module's "null" can be assigned only a configuration for hc-doc-sparkle/null, which is not required by
│ module.m.
╵
Terraform refuses to pass a provider instance for a requirement with a different source
, even if the two providers have identical interfaces (schemas).
If a child module doesn't specify source
, Terraform seems to effectively ignore the child module's required_providers
entry. Fix incoming!
And on a related note, this is something we'll be enforcing across all our modules soon!
https://github.com/terraform-linters/tflint-ruleset-terraform/pull/64
Thanks for reporting this @jkinkead! Please try version = "1.2.3"
, that should resolve this. In the very unlikely event it doesn't, go ahead and reopen this and we can investigate.
When submitting a provider to this module, terraform produces a warning about undefined providers.
For example, terraform like:
Will produce a warning like:
I think the suggested remediation (add a "source") should solve this (docs).