gpt4 book ai didi

amazon-web-services - 错误 : Invalid Index The given key does not identify an element in this collection value Transit gateway routes

转载 作者:行者123 更新时间:2023-12-05 04:48:47 25 4
gpt4 key购买 nike

我正在尝试在中转网关路由表中创建路由。下面是代码块。

locals {
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" "route" {
count = var.create_tgw ? 1 : 0
transit_gateway_id = aws_ec2_transit_gateway.this[0].id
}

resource "aws_ec2_transit_gateway_route" "this" {
count = length(local.vpc_attachments_with_routes)

destination_cidr_block = local.vpc_attachments_with_routes[count.index][1]["destination_cidr_block"]
blackhole = lookup(local.vpc_attachments_with_routes[count.index][1], "blackhole", null)

transit_gateway_route_table_id = aws_ec2_transit_gateway_route_table.route[count.index].id
transit_gateway_attachment_id = tobool(lookup(local.vpc_attachments_with_routes[count.index][1], "blackhole", false)) == false ? aws_ec2_transit_gateway_vpc_attachment.this[local.vpc_attachments_with_routes[count.index][0]["key"]].id : null
depends_on = [
aws_ec2_transit_gateway_route_table.route,
]
}

错误:

错误:无效索引\n\n 在 ../modules/tgw/main.tf 第 85 行,在资源“aws_ec2_transit_gateway_route”“this”中:\n 85:transit_gateway_route_table_id = aws_ec2_transit_gateway_route_table.route[count.index].id\n |----------------\n | aws_ec2_transit_gateway_route_table.route 是包含 1 个元素的元组\n | count.index 为 1\n\n给定的键未标识此集合值中的元素。\n\n",

最佳答案

您将只有 0 或 1 个 aws_ec2_transit_gateway_route_table.route,具体取决于 create_tgw 的值。所以应该是:

resource "aws_ec2_transit_gateway_route" "this" {
count = length(local.vpc_attachments_with_routes)

destination_cidr_block = local.vpc_attachments_with_routes[count.index][1]["destination_cidr_block"]
blackhole = lookup(local.vpc_attachments_with_routes[count.index][1], "blackhole", null)

transit_gateway_route_table_id = var.create_tgw ? aws_ec2_transit_gateway_route_table.route[0].id : null

transit_gateway_attachment_id = tobool(lookup(local.vpc_attachments_with_routes[count.index][1], "blackhole", false)) == false ? aws_ec2_transit_gateway_vpc_attachment.this[local.vpc_attachments_with_routes[count.index][0]["key"]].id : null
}

关于amazon-web-services - 错误 : Invalid Index The given key does not identify an element in this collection value Transit gateway routes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67897564/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com