我正在尝试将目标组附加到 terraform 中的负载均衡器,但出现以下错误:
resource "aws_lb_target_group" "mytargetgroup" {
count = var.environment_acronym == "pd" ? 1 : 0
name = "My Target Group"
port = 80
protocol = "HTTP"
vpc_id = var.vpc_main_id
}
resource "aws_lb_target_group_attachment" "mytargetgroup_attachment" {
target_group_arn = aws_lb_target_group.mytargetgroup[0].arn --> having issues here
target_id = var.private_admin
port = 80
}
错误:lb_tg_attachments\lb_public_myloadbalancer_attach.tf 第 70 行的索引无效,在资源“aws_lb_target_group_attachment”“mytargetgroup_attachment”中:70:target_group_arn = aws_lb_target_group.mytargetgroup[0].arn ├───────────── ─ │ aws_lb_target_group.mytargetgroup 为空元组
The given key does not identify an element in this collection value.
我怎样才能避免这个错误。任何建议表示赞赏。
uj5u.com热心网友回复:
你的条件var.environment_acronym == "pd"
一定是假的,所以aws_lb_target_group
不存在。因此它不起作用。您还必须稍后检查它:
resource "aws_lb_target_group_attachment" "mytargetgroup_attachment" {
count = var.environment_acronym == "pd" ? 1 : 0
target_group_arn = aws_lb_target_group.mytargetgroup[0].arn --> having issues here
target_id = var.private_admin
port = 80
}
0 评论