google-cloud-platform - 无法将“google_dns_record_set”从 count 转换为 for_each
问题描述
尝试将我的模块升级到 Tf0.12 运行后terraform 0.12upgrade
,现在无法转换count
为for_each
带计数的原始模块
resource "google_dns_record_set" "default" {
count = length(var.account_fqdns)
name = "${element(var.account_fqdns, count.index)}."
type = "A"
ttl = 300
managed_zone = var.dns_managed_zone
project = var.dns_project
rrdatas = [element(google_compute_address.default2.*.address, count.index)]
}
我的新模块
resource "google_dns_record_set" "default" {
for_each = {for fqdn in var.account_fqdns: fqdn => fqdn}
name = each.key
type = "A"
ttl = 300
managed_zone = var.dns_managed_zone
project = var.dns_project
rrdatas = [google_compute_address.default2.*.address]
}
运行计划时,我不断遇到以下错误
Error: Incorrect attribute value type
on main.tf line 285, in resource "google_dns_record_set" "default":
285: rrdatas = [google_compute_address.default2.*.address]
|----------------
| google_compute_address.default2 is object with 3 attributes
Inappropriate value for attribute "rrdatas": element 0: string required.
Error: Unsupported attribute
on main.tf line 285, in resource "google_dns_record_set" "default":
285: rrdatas = [google_compute_address.default2.*.address]
This object does not have an attribute named "address".
解决方案
我可以通过在下面执行此操作来解决我的问题
rrdatas = [for ip in google_compute_address.default2: ip.address]
推荐阅读
- python - 在 Python 中需要函数帮助
- node.js - 为什么在尝试部署 Express 应用程序时仍然出现 R10 错误
- visual-studio-code - 在 ssh 模式下复制到 vscode 终端中的本地剪贴板
- html - 让所有内容都以不同的浏览器分辨率为中心
- r - 用于在向量中查找区间总和的 R 函数神秘地返回数字(0),但手动工作正常
- swift - 无法将数据从 Firestore 加载到 uitableview
- php - 如何在 FormRequest Laravel 中添加参数
- html - 当页面向下滚动时,从应用程序组件移动到Angular中的单独组件时的侧边栏没有页面的完整高度
- math - 计算相对于另一个相机的方位角和仰角
- java - 如何保存 RecyclerView 的滚动位置?应用关闭时