Using flatten on a nested map of differing value types

i am able to the fix the issue.

variable "vpc_peer" {
  description = "An object that contains all the groups that should be created in the project"
  type        = map(any)
  default     = {
      vpc_peer1: {
        aws_account_id : "209769635771"
        region  : "eu-central-1"
        route_table_cidr_block : "10.57.0.0/16"
        route_table_ids: ["rtb-1", "rtb-2", "rtb-3", "rtb-4"]
        vpc_id: "vpc-id-1"
      },
      vpc_peer2: {
        aws_account_id : "2097696jddddd"
        region  : "eu-west-1"
        route_table_cidr_block : "10.100.0.0/16"
        route_table_ids: [ "rtb-20", "rtb-21" ]
        vpc_id: "vpc-id-3"
      }

  }
}
locals {
  vpc_peering = flatten([
    for vpc_peers, vpc_peer_ids in var.vpc_peer : [
       for route_table_id in vpc_peer_ids.route_table_ids : {
       aws_account_id          = vpc_peer_ids.aws_account_id
       region                  = vpc_peer_ids.region
       route_table_cidr_block  = vpc_peer_ids.route_table_cidr_block
       vpc_id                  = vpc_peer_ids.vpc_id
       route_table_ids         = route_table_id
       peering_id              = mongodbatlas_network_peering.mongoatlas_peer[vpc_peers].connection_id
       }
    ]
  ])
}
resource "aws_route" "mongoatlas_route" {
  for_each = { for route_id in local.vpc_peering : route_id.route_table_ids => route_id }

  route_table_id            = each.value.route_table_ids
  destination_cidr_block    = var.atlas_vpc_cidr
  vpc_peering_connection_id = each.value.peering_id
}

Thanks

1 Like