Terraform split subnets between 2 route tables
I have created a large amount of azure subnets with terraform, but i need to split them all between 2 route tables.
Currently i have my code like this, but of course the output from the resource is not a list, but objects.
resource "azurerm_subnet_route_table_association" "subnet-to-rt1" {
for_each = tolist(chunklist(azurerm_subnet.subnets, 255)[0])
subnet_id = (chunklist(azurerm_subnet.subnets, 20)[0])[each.key].id
route_table_id = module.spoke.route_table_1
}
resource "azurerm_subnet_route_table_association" "subnet-to-rt2" {
for_each = tolist(chunklist(azurerm_subnet.subnets, 20)[1])
subnet_id = (chunklist(azurerm_subnet.subnets, 20)[1])[each.key].id
route_table_id = module.spoke.route_table_2
}
Edit: Code to generate the subnets for clarity of the problem. I provide the var.spoke_cidr in an slash /18 range to get /27's
resource "azurerm_subnet" "subnets" {
for_each = toset(slice(cidrsubnets(var.spoke_cidr, [for v in range(20) : 9]...), 2, length(cidrsubnets(var.spoke_cidr, [for v in range(20) : 9]...))))
name = "az-subnet-${index(slice(cidrsubnets(var.spoke_cidr, [for v in range(20) : 9]...), 2, length(cidrsubnets(var.spoke_cidr, [for v in range(20) : 9]...))), each.key)}"
resource_group_name = module.spoke.azure_rg.name
virtual_network_name = module.spoke.vnet.name
address_prefixes = [each.value]
}
The error code im getting for each route table association resource is
Invalid value for "list" parameter: list of any single type required.
Does anyone know how i can fix this route table associations Thanks!
from Recent Questions - Stack Overflow https://ift.tt/3c2PVOH
https://ift.tt/eA8V8J
Comments
Post a Comment