Dynamic providers for multi-region setups

I’m building a service which will be multi-region in AWS, but will be identical across those regions. Since Terraform will generally only handle AWS regions in the provider block as opposed to individual resources, I originally planned to have various aliased AWS providers, and have my resources use a count argument with the provider name as a variable from a list.

Unfortunately, it appears that because the provider name is not treated as a string, you can’t have anything other than provider.alias with no quotes and no functions of any sort after the provider = argument. What’s more, the provider definition itself can’t use count or for_each or anything like that, so I can’t create a list variable to only define appropriate providers on a per-environment basis.

I really don’t want to replicate code for every region or script this out- it would violate our standards and disrupt our workflow. This can’t be an uncommon problem, but so far I haven’t found any interesting solutions to it. Any ideas?

1 Like

Hi

Did you every find a solution? I feel you are on the same path as this comment.

I want to do the same thing, I setup AWS ControlTower in my master account, this has created an organisation. I now have an AccountVendingMachine (AVM) and I would like my terraform to dynamically find accounts and based on tags deploy resources in the right region, etc.

Thanks