Hello, I’ve created a route table, and I would like to use mapping, however some of values inside of map is list of strings, and couldn’t find a solution to manage it.
Here is the main.tf
resource "aws_route" "ipv4" {
count = length(aws_route_table.route)
depends_on = [ aws_route_table.route ]
route_table_id = aws_route_table.route[count.index].id
gateway_id = lookup(var.ipv4, "igw", "")
nat_gateway_id = lookup(var.ipv4, "nat", "")
destination_ipv6_cidr_block = lookup(var.ipv4, "target", "")
}
resource "aws_route" "ipv6" {
count = length(aws_route_table.route)
depends_on = [ aws_route_table.route ]
route_table_id = aws_route_table.route[count.index].id
gateway_id = lookup(var.ipv6, "igw", "")
egress_only_gateway_id = lookup(var.ipv6, "egw", "")
destination_ipv6_cidr_block = lookup(var.ipv6, "target", "")
}
variable "ipv4" {
type = map(string)
default = null
}
variable "ipv6" {
type = map(string)
default = null
}
Here is how I’m defining the values
Notice that, if value contains string only, no issue
The issue with nat gateway id, as I have multiple nat gateways
locals {
ipv4 = {
public = {
target = "0.0.0.0/0"
igw = module.internet_gateway.igw_ids # No Issue
}
private = {
target = "0.0.0.0/0"
nat = module.translate_gateway.nat_ids # << Here is the list of strings
}
}
ipv6 = {
public = {
target = "::/0"
igw = module.internet_gateway.igw_ids # No Issue
}
private = {
target = "::/0"
nat = compact(module.private_subnets.ipv6_cidrblock) != [] ? null : module.internet_gateway.egw_ids # No Issue
}
}
}
I think I need to somehow make count.index
on that lookup block, but I don’t know how
3 posts - 2 participants