I have a route_table variable containing route table objects which each have several route objects.
variable "route_tables" {
description = "a map of route tables"
type = map(any)
default = {
"route_table01" = {
name = "route_table01"
route = {
name = "route1"
address_prefix = "17.65.255.0/24"
next_hop_type = "VirtualAppliance"
next_hop_in_ip_address = "10.18.128.6"
}
route = {
name = "route2"
address_prefix = "204.61.3.87/32"
next_hop_type = "VirtualAppliance"
next_hop_in_ip_address = "10.18.128.6"
}
route = {
name = "route3"
address_prefix = "13.61.37.248/29"
next_hop_type = "VirtualAppliance"
next_hop_in_ip_address = "10.18.128.6"
}
}
}
}
I'm now trying to loop over them in my module:
resource "azurerm_route_table" "route_tables" {
for_each = var.route_tables
name = each.value.name
location = azurerm_resource_group.resource_group.location
resource_group_name = azurerm_resource_group.resource_group.name
tags = local.tags
dynamic "route" {
for_each = each.value.route
content {
name = each.value.route.name
address_prefix = each.value.route.address_prefix
next_hop_type = each.value.route.next_hop_type
next_hop_in_ip_address = each.value.route.next_hop_in_ip_address
}
}
}
The tf plan completes successfully, but only 1 route is being added to the route table:
How can I loop over these routes so that all of them are added to the route table?
