Hello, again. I’ve created a route table
however routes it self assigning only to the first route table
, while I have 3 of them (The length of Availability zones).
So aws_route_table
has been created with count
and the aws_route
with for_each
Now when I’m trying to assign route_table_id
from aws_route_table
it takes only 1st id
is there any way to map properly?
Here is my code:
resource "aws_route_table" "public" {
count = length(local.routing.public.ipvf)
vpc_id = lookup(var.parameters[0], "network", "")
tags = var.tag_map
}
–
resource "aws_route" "public_ipv4" {
for_each = { for idx, route in local.routing.public : idx => route }
route_table_id = element([ for key, value in aws_route_table.public : value.id ], each.key) << Here is the problem
gateway_id. = lookup(each.value, "internet", "" )
instance_id = lookup(each.value, "instance", "" )
nat_gateway_id = element(concat(compact(split(",", lookup(each.value, "nat", ""))), [""]), each.key)
vpc_endpoint_id = lookup(each.value, "endpoint", "" )
local_gateway_id = lookup(each.value, "local", "" )
transit_gateway_id = lookup(each.value, "transit", "" )
network_interface_id = lookup(each.value, "interface", "" )
vpc_peering_connection_id = lookup(each.value, "peering", "" )
destination_cidr_block = lookup(each.value, "cidrblock", "" )
}
–
locals { routing = { public = [ { name = "Public Route Table IPv4 - With ${local.network.gateway.name[0].internet}" nat = module.gateways.nat_ids cidrblock = "120.0.10.0/0" } ] }
As said already the code is working, but route_table_id assigning only 1st id of route table
Here is the proof of, that other resources are exists
+ nat_list = [
+ "nat-0980ffedd5471b76d",
+ "nat-053701e207f6e92b2",
+ "nat-0be06d45baf164edc",
]
+ subnets = [
+ "subnet-04c920f8908d7e502",
+ "subnet-0e9e9333180cab627",
+ "subnet-0caae55b544e4b63d",
]
Public Subnet · 10.0.16.0/24 | EU-WEST-1A
Public Subnet · 10.0.32.0/24 | EU-WEST-1B
Public Subnet · 10.0.48.0/24 | EU-WEST-1C
Public Route · 10.0.16.0/24 | EU-WEST-1A
Public Route · 10.0.32.0/24 | EU-WEST-1B
Public Route · 10.0.48.0/24 | EU-WEST-1C
NAT Gateway · 10.0.16.0/24 | EU-WEST-1A
NAT Gateway · 10.0.32.0/24 | EU-WEST-1B
NAT Gateway · 10.0.48.0/24 | EU-WEST-1C