OK, this is all making sense now… it’s pretty complicated, so I’ll try to break it down:
First, let’s talk about your original error message:
In the early days of Terraform, it was allowed to define provider configurations in the root module, or in child modules. However, it later became clear that there were problems with allowing provider configurations to be specified in child modules. (You can read more about this in Providers in Modules? for background information, if you like.)
When support for count
, for_each
, and depends_on
was added to module
blocks, it was decided to only support them for child modules which did NOT define their own provider configurations.
You receive the error because you have attempted to use count
, but your child module defines provider configurations.
However, your child module doesn’t seem to actually be using the provider configurations it defines!
In the root module, you set up two provider configurations:
and then in each of the module blocks you showed, you include:
By writing this, you are telling Terraform that the child module’s default aws
provider configuration (with no alias) should be the root module’s aws.sharedservices
provider configuration - effectively you’re passing the provider configuration by reference, effectively renaming it within the child module.
When I look at the resource
blocks from the child module that you shared, I don’t see any lines looking like
provider = aws.something
This tells me that everything in the child module is using the default (no alias) aws
provider there. That means that the extra provider "aws"
configuration blocks in the child module are in fact completely redundant and should be removed!
Since these redundant provider configurations are what are causing Terraform to block the usage of count
on your module in the first place, cleaning up this redundancy should solve your problem!