gpt4 book ai didi

amazon-web-services - 在 terraform 中,如何输出 aws_route53_record 别名值?

转载 作者:行者123 更新时间:2023-12-03 08:31:54 24 4
gpt4 key购买 nike

Terraform v0.12.x

我正在创建一个 AWS Route53 记录,如下所示,它的创建没有任何问题。

data "aws_route53_zone" "zone" {
name = "my.domain.com."
private_zone = true
}

resource "aws_route53_record" "record" {
zone_id = data.aws_route53_zone.zone.zone_id
name = "${var.record_name}.${data.aws_route53_zone.zone.name}"
type = "A"
alias {
name = var.alias_record
zone_id = var.alias_zone_id
evaluate_target_health = false
}
}

现在我想输出别名的值,我尝试了

output "alias_name" {
value = aws_route53_record.record.alias.name
}

output "alias_name" {
value = aws_route53_record.record.alias["name"]
}

但出现错误

Block type "alias" is represented by a set of objects, and set elements do not
have addressable keys. To find elements matching specific criteria, use a
"for" expression with an "if" clause.

正确的语法是什么?

最佳答案

别名是一组对象和集合 are :

a collection of unique values that do not have any secondary identifiers or ordering.

所以你无法对它们建立索引。因此,在您的情况下,要输出可以使用的别名值:

output "alias_name" {
value = aws_route53_record.record.alias.*.name
}

# or

output "alias_name2" {
value = aws_route53_record.record.alias[*].name
}

关于amazon-web-services - 在 terraform 中,如何输出 aws_route53_record 别名值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64852981/

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