拨开荷叶行,寻梦已然成。仙女莲花里,翩翩白鹭情。
IMG-LOGO
主页 文章列表 获取无效索引和空元组错误

获取无效索引和空元组错误

白鹭 - 2022-01-24 2097 0 0

我正在尝试将目标组附加到 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 评论

发表评论

您的电子邮件地址不会被公开。 必填的字段已做标记 *