AWS provider for_each

Issue being able to deploy resources to multiple regions within the same AWS account. My flattened list of maps works as expected, however since the provider block sits outside of the for_each loop, is there a way to access the nested map with a lookup?

Or if I scrapped the for_each and created a map with regions as keys? However i’ve been unsuccessful with accessing the map and keys when it’s nested a few levels deep.

Examples:

Map:

variable "create_vpcs" {
  description = "Map of vpc's to create"
  default = {
    acccount = {
      regions = {
        us-east-1 = {
          name               = "tw-vpc-ue1-test"
          cidr               = "10.0.0.0/27"
          azs                = ["us-east-1a", "us-east-1b"]
          private_subnets    = ["10.0.0.0/28"]
          public_subnets     = ["10.0.0.16/28"]
          enable_nat_gateway = true
          single_nat_gateway = true
          tags = {
            Info = "terraformed for xxxxxx"
          }
        },
         us-west-1 = {
           name = "tw-vpc-uw1-test"
           cidr = "10.0.0.0/27"
           azs = ["us-west-1a", "us-west-1b"]
           private_subnets = ["10.0.0.0/28"]
           public_subnets = ["10.0.0.16/28"]
           enable_nat_gateway = true
           single_nat_gateway = true
           tags = {
             Info = "terraformed for xxxxxxx"
           }
         }
      }
    }
  }
}

Flatten Map:

locals {
  create_vpcs_flatten = flatten([
    for account, account_values in var.create_vpcs : [
      for region, region_values in account_values.regions : {
        account            = account,
        region             = region,
        name               = region_values.name,
        cidr               = region_values.cidr,
        azs                = region_values.azs,
        private_subnets    = region_values.private_subnets,
        public_subnets     = region_values.public_subnets,
        enable_nat_gateway = region_values.enable_nat_gateway,
        single_nat_gateway = region_values.single_nat_gateway,
        tags               = region_values.tags,
      }
    ]
  ])
}

MODULE Call:

module "vpc" {
for_each = {for el in local.create_vpcs_flatten : "${el.account}-${el.region}-${el.name}" => el}
  name = each.value.name
  cidr = each.value.cidr
  azs             = each.value.azs
  private_subnets = each.value.private_subnets
  public_subnets  = each.value.public_subnets
  enable_nat_gateway = each.value.enable_nat_gateway
  single_nat_gateway = each.value.single_nat_gateway
  tags = each.value.tags
}

The behavior is that it attempts to create everything in us-east-1, based on the provider declaration. Any direction would be helpful.
I’ve tried to do a for_each on the provider block, but it errored out as “reserved for future”.

Impossible to iterate over providers right now, but you could add provider each resource you are trying to create or use alias with provider block

Thanks @r11: Yes I’ve also looked into that as well. Appreciate the feedback and the confirmation on the impossibility of my previous approach.