amazon-web-services - 当我尝试在端点定义中设置 dns_entry 时,Terraform 得到 `Error: Computed attribute cannot be set`

标签 amazon-web-services terraform amazon-route53

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_namehosted_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/

相关文章:

amazon-web-services - 如何通过Amazon Route 53映射带有端口号的URL

javascript - 存储在aws polly上提取的音频,将其存储在S3上并将其上传到Javascript中的html元素上

azure - 使用租户中的资源配置 azure ad b2c

amazon-web-services - 如何使用 Terraform 标记从自动缩放启动的实例?

docker - 使用 Golang docker SDK - Interactive Container 接受用户输入 os.stdin 到容器

amazon-web-services - 使用自定义 DHCP 选项集查询 Route53 私有(private)托管区域

amazon-web-services - 如何将弹性 IP 重复用于一组专用于 Fargate 任务的私有(private)和公有子网

amazon-web-services - 使用 PySpark 将数据上传到 Redshift

amazon-web-services - s3 预签名 url 多部分表单数据上传错误 :signature does not match

ruby - 如何使用适用于 ruby​​ 的 aws sdk 创建 route53 记录集?