Are there plans to relax the restriction on nested providers in modules used with count
or for_each
? For providers such as random or null, requiring the top level module to instantiate providers seems like an unfortunate abstraction violation. Even more so given that instantiating the module without a count doesn’t have the restriction.
Example submodule:
provider "random" {}
and a top level
module "sub" {
source = "./submodule"
count = 2
}
This leads to the unfortunate situation
$ terraform apply
Error: Module does not support count
on main.tf line 11, in module "submodule":
11: count = 2
Module "submodule" cannot be used with count because it contains a nested
provider configuration for "random", at sub/main.tf:3,10-18.
This module can be made compatible with count by changing it to receive all of
its provider configurations from the calling module, by using the "providers"
argument in the calling module block.
Taking it a step stranger, using count with a module that doesn’t have any providers but uses modules with providers is allowed.
main.tf
module "submodule" {
source = "./sub"
count = 2
}
sub/main.tf
module "submodule" {
source = "../sub2"
}
sub2/main.tf
provider "null" {}
resource "null_resource" "demo" {
}
terraform apply -auto-approve
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# module.submodule[0].module.submodule.null_resource.demo will be created
+ resource "null_resource" "demo" {
+ id = (known after apply)
}
# module.submodule[1].module.submodule.null_resource.demo will be created
+ resource "null_resource" "demo" {
+ id = (known after apply)
}
Plan: 2 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
module.submodule[0].module.submodule.null_resource.demo: Creating...
module.submodule[1].module.submodule.null_resource.demo: Creating...
module.submodule[0].module.submodule.null_resource.demo: Creation complete after 0s [id=3699949161487192158]
module.submodule[1].module.submodule.null_resource.demo: Creation complete after 0s [id=8321835071609336736]
Apply complete! Resources: 2 added, 0 changed, 0 destroyed.