SuperBuker / terraform-provider-dns-he-net

Hurricane Electric DNS Terraform Provider
https://registry.terraform.io/providers/SuperBuker/dns-he-net/latest
GNU General Public License v3.0
3 stars 1 forks source link

Plan fails when using for_each and each.value.IPAddress for data #66

Open bardahlm opened 10 months ago

bardahlm commented 10 months ago

I'm trying to create multiple a-records. I populate an array with values:

locals {
  he_net_test = {
    "test1" = {
      Hostname   = "test1"
      Domainname = "subdomain.domain.tld
      IPAddress  = "192.168.88.35"
    }
    "test2" = {
      Hostname   = "test2"
      Domainname = "subdomain.domain.tld"
      IPAddress  = "192.168.88.36"
    }
  }
}

I then apply those values to a resource:

resource "dns-he-net_a" "containers" {
  for_each = local.he_net_test
  zone_id  = 123456
  domain   = format("%s.%s", each.value.Hostname, each.value.Domainname)
  ttl      = 86400
  data     = each.value.IPAddress
}

But this fails with:

| Error: Invalid A record configuration
│
│   with dns-he-net_a.containers,
│   on dns.tf line 37, in resource "dns-he-net_a" "containers":
│   37: resource "dns-he-net_a" "containers" {
│
│ Static A records must have Data configured.

This passes plan, though:

resource "dns-he-net_a" "containers" {
  for_each = local.he_net_test
  zone_id  = 123456
  domain   = format("%s.%s", each.value.Hostname, each.value.Domainname)
  ttl      = 86400
  data     = "192.168.1.2"
}

(but will configure the wrong IP address)

SuperBuker commented 10 months ago

Hi @bardahlm, I've managed to reproduce the issue and I'm looking for a fix.
The bug affecting A records is located in A.go#L293, although all the dynamic records are also affected.
Long story short, when the for_each meta-argument is set, the ValidateConfig function receives an incomplete record, and fails as if the user hadn't filled the minimum required fields.
On that side there's nothing I can do as it's how the Terraform provider framework currently works. I'm in the process of migrating the code from resource.ConfigValidator to resource.ResourceWithConfigValidators, but it's going to take some time and it may not fix the issue. More info is about resources validation is available here.