Terraform v0.13.5
+ provider registry.terraform.io/hashicorp/aws v3.16.0
描述
我想要创建一个端点并将其设置到 Route53 记录中。
我将在域中部署 Kubernetes 集群。
我收到此错误。
$ terraform plan
Error: Computed attribute cannot be set
on route53.tf line 24, in resource "aws_vpc_endpoint" "endpoint":
24: dns_entry = [
25: {
26: "dns_name" = "vpce",
27: "hosted_zone_id" = "ap-northeast-1a"
28: },
29: ]
resource "aws_route53_zone" "primary" {
name = local.cluster_name
}
resource "aws_route53_record" "cluster" {
zone_id = aws_route53_zone.primary.zone_id
name = local.cluster_name
type = "CNAME"
ttl = 30
records = [aws_vpc_endpoint.endpoint.dns_entry[0]["dns_name"]]
}
resource "aws_vpc_endpoint" "endpoint" {
vpc_id = module.vpc.vpc_id
service_name = "com.amazonaws.ap-northeast-1.ec2"
vpc_endpoint_type = "Interface"
security_group_ids = [
module.vpc.default_security_group_id,
]
subnet_ids = [
module.vpc.public_subnets
]
private_dns_enabled = false
dns_entry = [
{
"dns_name" = "vpce",
"hosted_zone_id" = "ap-northeast-1a"
},
]
}
我尝试了什么
如果我删除 dns_entry block ,则会收到此错误。
Error: Invalid index
on route53.tf line 10, in resource "aws_route53_record" "cluster":
10: records = [aws_vpc_endpoint.endpoint.dns_entry[0]["dns_name"]]
|----------------
| aws_vpc_endpoint.endpoint.dns_entry is empty list of object
The given key does not identify an element in this collection value.
我想知道什么
在没有 terraform 的情况下手动创建端点的情况下,我成功并获得了此 DNS 名称 vpce-0814cfe7cf6dd0f57-t6i209re.ec2.ap-northeast-1.vpce.amazonaws.com
我想使用 Terraform 将类似的 DNS 名称设置到 Route53 记录中。
如何修复错误并设置 DNS 名称?
最佳答案
dns_entry
是创建 aws_vpc_endpoint
后返回给您的内容。这不是您可以自己设置的。
获取接口(interface)端点的 dns_name
和 hosted_zone_id
:
aws_vpc_endpoint.endpoint.dns_entry[0].dns_name
aws_vpc_endpoint.endpoint.dns_entry[0].hosted_zone_id
通常您的数量会超过 1 个,因此您必须迭代 aws_vpc_endpoint.endpoint.dns_entry
或将它们作为列表获取。
关于amazon-web-services - 当我尝试在端点定义中设置 dns_entry 时,Terraform 得到 `Error: Computed attribute cannot be set`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64941569/