Terraform 从地形资源创建记录列表

Terraform 从地形资源创建记录列表,terraform,Terraform,在Terraform中,我试图从创建的DNS a记录创建DNS SRV记录。我想用aws_route53_record.etcd名称填充记录,但在引用资源名称时遇到错误 有没有一个简单的方法来实现这一点 # This resource works without errors resource "aws_route53_record" "etcd" { count = length(var.control_plane_private_ips)

在Terraform中,我试图从创建的DNS a记录创建DNS SRV记录。我想用aws_route53_record.etcd名称填充记录,但在引用资源名称时遇到错误

有没有一个简单的方法来实现这一点

# This resource works without errors
resource "aws_route53_record" "etcd" {

  count = length(var.control_plane_private_ips)
  
  zone_id = data.aws_route53_zone.test.zone_id
  name    = "etcd-${count.index}.${data.aws_route53_zone.test.name}"
  type    = "A"
  ttl     = 60
  records = var.control_plane_private_ips

}

resource "aws_route53_record" "etcd_ssl_tcp" {

  zone_id = data.aws_route53_zone.test.zone_id
  name    = "_etcd-server-ssl._tcp.${data.aws_route53_zone.test.name}"
  type    = "SRV"
  ttl     = 60

  # code is producing an error here. Would like to add the names to the records
  for_each = [for n in aws_route53_record.etcd : { name = n.name }]
  records = [
    "0 10 2380 ${each.value.name}.${data.aws_route53_zone.test.name}"
  ]
 
}
当运行
地形平面图时,我得到以下错误

Error: Invalid for_each argument

  on main.tf line 55, in resource "aws_route53_record" "etcd_ssl_tcp":
  55:   for_each = [for n in aws_route53_record.etcd : { name = n.name }]

The given "for_each" argument value is unsuitable: the "for_each" argument
must be a map, or set of strings, and you have provided a value of type tuple.

您对同一行中的每个
和使用
。两者都在描述循环,这使得休耕变得非常困难。尝试将该行拆分为两行,并将for指定给局部变量。拆分for和for_将帮助我们检查这一点

我认为问题是
[对于aws_route53_record.etcd:{name=n.name}中的n]

起始括号
[用于…
定义了一个列表和
{name..
定义了一个映射。因此一个映射列表。也许要删除
{

根据反馈找到它。感谢您的帮助

resource "aws_route53_record" "etcd_ssl_tcp" {

  zone_id = data.aws_route53_zone.kubic.zone_id
  name    = "_etcd-server-ssl._tcp.${data.aws_route53_zone.test.name}"
  type    = "SRV"
  ttl     = 60

  records = [
      for n in aws_route53_record.etcd :
      "0 10 2380 ${n.name}"
  ]

}

什么错误?请发布您收到的具体错误。用错误更新。