I am trying to fetch route table ids and running into some issues. any help would be appreciated.
data "aws_subnet_ids" "private" {
vpc_id = data.aws_vpc.selected.id
filter {
name = "tag:Name"
values = ["*.private.xxx.xxxx.xxxx.com"]
}
}
data "aws_route_table" "selected" {
for_each = data.aws_subnet_ids.private.ids
subnet_id = each.value
}
resource "aws_route" "private_connection" {
for_each = {
for pair in setproduct(
[for name, subnet in var.private_subnets : name],
[for peer in var.peers : peer.vpc_id]
) : "${pair[0]}-${pair[1]}" => { net = pair[0], id = pair[1] } }
route_table_id = data.aws_route_table.selected[each.key]
destination_cidr_block = data.aws_vpc_peering_connection.peer[each.value.id].peer_cidr_block
vpc_peering_connection_id = aws_vpc_peering_connection.peer[each.value.id].id
}
The error i am getting is -
│ Error: Invalid index
│
│ 128: route_table_id = data.aws_route_table.selected[each.key]
│ ├────────────────
│ │ data.aws_route_table.selected is object with 2 attributes