Ошибка aws_alb_target_group имеет "count", ее атрибуты должны быть доступны на определенных c экземплярах - PullRequest
1 голос
/ 17 июня 2020

Я использую Terraform v0.12.26 и настраиваю aws_alb_target_group как:

resource "aws_alb_target_group" "my-group" {
  count = "${length(local.target_groups)}"
  name = "${var.namespace}-my-group-${
    element(local.target_groups, count.index)
  }"

  port     = 8081
  protocol = "HTTP"
  vpc_id   = var.vpc_id

  health_check {
    healthy_threshold   = var.health_check_healthy_threshold
    unhealthy_threshold = var.health_check_unhealthy_threshold
    timeout             = var.health_check_timeout
    interval            = var.health_check_interval
    path                = var.path
  }

  tags = {
    Name = var.namespace
  }

  lifecycle {
    create_before_destroy = true
  }
}

Локальные жители выглядят так:

locals {
  target_groups = [
    "green",
    "blue",
  ]
}

Когда я запускаю terraform apply, он возвращает следующая ошибка:

Error: Missing resource instance key

  on ../../modules/aws_alb/outputs.tf line 3, in output "target_groups_arn":
   3:     aws_alb_target_group.http.arn,

Because aws_alb_target_group.http has "count" set, its attributes must be
accessed on specific instances.

For example, to correlate with indices of a referring resource, use:
    aws_alb_target_group.http[count.index]

Я следил за этой реализацией

Есть идеи, как это исправить?

Вывод

output "target_groups_arn" {
  value = [
    aws_alb_target_group.http.arn,
  ]
}

1 Ответ

1 голос
/ 18 июня 2020

Поскольку aws_alb_target_group.http является подсчитываемым ресурсом, вам нужно будет ссылаться на определенные c экземпляры по индексу или на все из них в виде списка с [*] (также известного как Splat Expressions ) следующим образом:

output "target_groups_arn" {
  value = aws_alb_target_group.http[*].arn,
}

Вывод target_groups_arn будет списком TG ARN.

...