Mai*_*aik 3 amazon-web-services terraform aws-alb
我正在使用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
}
}
Run Code Online (Sandbox Code Playgroud)
当地人长这样:
locals {
target_groups = [
"green",
"blue",
]
}
Run Code Online (Sandbox Code Playgroud)
当我运行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]
Run Code Online (Sandbox Code Playgroud)
我遵循了这个实现
知道如何修复它吗?
输出
output "target_groups_arn" {
value = [
aws_alb_target_group.http.arn,
]
}
Run Code Online (Sandbox Code Playgroud)
由于aws_alb_target_group.http是一个计数资源,您需要通过索引或所有这些实例作为列表[*](又名Splat Expressions)引用特定实例,如下所示:
output "target_groups_arn" {
value = aws_alb_target_group.http[*].arn,
}
Run Code Online (Sandbox Code Playgroud)
该target_groups_arn输出将是TG ARNS的列表。
| 归档时间: |
|
| 查看次数: |
3461 次 |
| 最近记录: |