# Locals =======================================================================

locals {
  module_tags = {
    managed-by  = "terraform"
    module-name = "networking:tgw-attachment"
  }

  # route_pairs builds a cartesian product of every VPC route table ID against
  # every destination CIDR, then route_map keys them as "rt_id:cidr" for stable
  # for_each iteration on aws_route.tgw.
  route_pairs = flatten([
    for rt_id in var.vpc_route_table_ids : [
      for cidr, _ in var.vpc_tgw_routes : {
        rt_id = rt_id
        cidr  = cidr
      }
    ]
  ])

  # Keyed by "rt_id:cidr" — unique and stable across applies
  route_map = {
    for pair in local.route_pairs :
    "${pair.rt_id}:${pair.cidr}" => pair
  }
}
