gpt4 book ai didi

amazon-web-services - 错误 aws_alb_target_group 设置了 "count",必须在特定实例上访问其属性

转载 作者:行者123 更新时间:2023-12-04 02:34:55 32 4
gpt4 key购买 nike

我正在使用 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]

我关注了 this implementation

知道如何修复它吗?

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

最佳答案

aws_alb_target_group.http 是一个计数资源,您需要通过索引引用特定实例或将它们全部作为列表引用 [*] (又名 Splat Expressions )如下:

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

target_groups_arn 输出将是 TG ARN 的列表。

关于amazon-web-services - 错误 aws_alb_target_group 设置了 "count",必须在特定实例上访问其属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62433708/

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