Reputation: 195
I am using the latest version of terraform and I'm trying to find a way to deploy an eventbridge forwarder to all regions in our AWS account.
I would like to do this dynamically so that when a new region gets created I don't need to update a static providers list.
I have the deployment in a module and I've been trying to loop over an aws_regions data section like this
data "aws_regions" "this" {}
module "eventbridge"{
for_each = toset([for region in data.aws_regions.this.names : "aws.${region}"])
source = "../../modules/eventbridge"
region = each.value
}
And having a providers section in the module that uses the region variable, but providers in modules are no longer permitted and i'm out of ideas now!
Can anyone suggest a way this can be done?
THANKS!
Upvotes: 0
Views: 394
Reputation: 238867
What you are trying to do (looping through providers) is simply not supported by TF. You have to explicitly list all modules for each provider you want to use, or create some external script which is going to pre-process your TF code and do that automatically.
Alternatively, you can use CloudFormation Stack Sets which is an easy way to deploy AWS resources across multiple regions and accounts.
Upvotes: 1