【问题标题】:Unable to transform `google_dns_record_set` from count to for_each无法将“google_dns_record_set”从 count 转换为 for_each
【发布时间】:2020-09-20 09:26:18
【问题描述】:

尝试将我的模块升级到 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".

【问题讨论】:

    标签: google-cloud-platform terraform-provider-gcp terraform0.12+


    【解决方案1】:

    我可以通过以下操作解决我的问题

    rrdatas      = [for ip in google_compute_address.default2: ip.address]
    

    【讨论】:

      猜你喜欢
      • 2020-08-31
      • 2022-01-17
      • 2013-10-11
      • 1970-01-01
      • 2019-05-07
      • 2013-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多