title: Terraform split subnets between 2 route tables
body: <p>I have created a large amount of azure subnets with terraform, but i need to split them all between 2 route tables.</p>
  <p>Currently i have my code like this, but of course the output from the resource is not a list, but objects.</p>
  <pre><code>resource &quot;azurerm_subnet_route_table_association&quot; &quot;subnet-to-rt1&quot; {
    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 &quot;azurerm_subnet_route_table_association&quot; &quot;subnet-to-rt2&quot; {
    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
  }
  </code></pre>
  <p>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</p>
  <pre><code>resource &quot;azurerm_subnet&quot; &quot;subnets&quot; {
    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                 = &quot;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)}&quot;
    resource_group_name  = module.spoke.azure_rg.name
    virtual_network_name = module.spoke.vnet.name
    address_prefixes     = [each.value]
  }
  </code></pre>
  <p>The error code im getting for each route table association resource is</p>
  <pre><code>Invalid value for &quot;list&quot; parameter: list of any single type required.
  </code></pre>
  <p>Does anyone know how i can fix this route table associations
  Thanks!</p>