Sam-Tahir
Sam-Tahir

Reputation: 191

Unable to transform `google_dns_record_set` from count to for_each

Attempting to upgrade my module to Tf0.12 After running the terraform 0.12upgrade, now failing to convert count to for_each

Original Module with count

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)]

}

My New module

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]
}

I keep running into the error below when I run plan

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".

Upvotes: 2

Views: 723

Answers (1)

Sam-Tahir
Sam-Tahir

Reputation: 191

I was able to solve my problem by doing this below

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

Upvotes: 2

Related Questions