我正在尝试在中转网关路由表中创建关联和路由。下面是代码块。
locals {
vpc_attachments_without_default_route_table_association = {
for k, v in var.vpc_attachments : k => v if lookup(v, "transit_gateway_default_route_table_association", true) != true
}
vpc_attachments_with_routes = chunklist(flatten([
for k, v in var.vpc_attachments : setproduct([{ key = k }], v["tgw_route"]) if length(lookup(v, "tgw_route", {})) > 0
]), 2)
}
resource "aws_ec2_transit_gateway_route_table" "this" {
count = var.create_tgw ? 1 : 0
transit_gateway_id = aws_ec2_transit_gateway.this[0].id
tags = merge(
{
"Name" = format("%s", var.name)
},
var.tags,
var.tgw_route_table_tags,
)
}
resource "aws_ec2_transit_gateway_route_table_association" "this" {
for_each = local.vpc_attachments_without_default_route_table_association
transit_gateway_attachment_id = aws_ec2_transit_gateway_vpc_attachment.this[each.key].id
transit_gateway_route_table_id = aws_ec2_transit_gateway_route_table.this[0].id
}
错误:错误:../modules/tgw/main.tf 第 118 行的无效索引\n\n,在资源“aws_ec2_transit_gateway_route_table_association”“this”中:\n 118:transit_gateway_route_table_id = aws_ec2_transit_gateway_route_table.this[0].id\n | ----------------\n | aws_ec2_transit_gateway_route_table。这是空元组\n\n给定的键未标识此集合值中的元素。\n\n"