ryanwholey / terraform-provider-pihole

A Terraform provider for managing Pi-hole resources
https://registry.terraform.io/providers/ryanwholey/pihole/latest/docs
Mozilla Public License 2.0
63 stars 9 forks source link

deletion of cname not always working #68

Open Jeffote opened 4 months ago

Jeffote commented 4 months ago

The deletion of "pihole_dns_record" is not always working and leaves the entry in pihole untouched.

pihole version: v5.17.3 provider version: 0.2.0

rustyguts commented 3 months ago

I ran into this when trying to add or remove lots of cnames from a list, though I get it with A records too. I converted my list to a set which solved the deletion issue. Now, Terraform is smart enough to only add or remove the domains that have changed. It may not fix the underlying cause but it's a workaround.

# Old
resource "pihole_cname_record" "this" {
  count  = length(local.all_cnames)
  domain = local.all_cnames[count.index]
  target = "ingress.example.local"
}

# New
resource "pihole_cname_record" "this" {
  for_each = toset(local.all_cnames)
  domain   = each.key
  target   = "ingress.example.local"
}