When writing examples for my Terraform module, I got the error: "Module contains provider configuration" "Providers cannot be configured within modules using count, for_each or depends_on."
I got this error when I tried to add a depends_on
block to the module's declaration to avoid trying to run the module plan before the creation of the resource group needed to deploy the resources inside the module.
If I don't add the depends_on
block it also breaks, because it can't find the declared resource group that should be created before the module runs to populate the required resource group data source.
I find it is at least uncomfortable to require the removal of the providers
block or to remove all the data sources.
I couldn't find any details on this error, or on how to fix it.
Specific line that raises this error inside Terraform's code.
Providers can be passed down to descendent modules in two ways: either implicitly through inheritance, or explicitly via the providers argument within a module block.
A provider configuration block is required in every Terraform configuration.
Each Terraform module must declare which providers it requires, so that Terraform can install and use them. Provider requirements are declared in a required_providers block.
The fact that Terraform is not tied to a specific infrastructure or cloud provider makes it a powerful tool in multi-provider deployments. You are able to manage all resources using the same set of configuration files, sharing variables or defining dependencies between resources across providers.
What you have probably looks similar to code below, right?
Root module (eg. terraform.tf):
---
... some code...
module "child_module" {
count = var.children_no
source = "./modules/childmodule.tf"
...
}
and
Child module (childmodule.tf)
---
... some code ...
provider "any_provider" {
...
}
So... the sad thing is... you can not do that. If module have any provider at all, you can not 'count' it. :/
That's basically what the error said. You either have to get your provider out of module or get out count
from root module.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With