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)
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}"
]
}
运行 a 时terraform plan
,出现以下错误。
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.
解决方案
根据反馈想出来的。谢谢您的帮助!
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}"
]
}
推荐阅读
- python-3.x - 嵌套列表中的嵌套字典到 Dataframe
- java - 在 appium 中寻找测试架构的想法
- oracle - 如何在 Apache Superset 上安装 Oracle 驱动程序(没有 Internet 访问权限)
- android - 当有 CANCEL、SEND 按钮时,Accessibilityservice 无法从 USSD 响应中关闭 AlertDialog
- jquery - 如何使用 JQuery 对单个表列进行排序?
- vue.js - 计算数据包发送/接收时间
- laravel - Laravel 新星 | 箭头函数 | 计算属性在 Tool.vue 中不起作用
- java - 反应原生问题 firebase 消息传递
- face-detection - 我如何在 android 应用程序上进行虚拟试戴
- r - 当多边形小于栅格单元时,terra::extract 给出 NaN