How to update NS records of a domain in GCP

domain : mildev.com. is already existing in GCP, all i am looking is to update NS records and its failing with record already exists.

data "google_dns_managed_zone" "selected" {
  name = "d-mildev-com"
}

locals {
  aws_name_servers = [
    "abc.cde.net.",
    "abc.cde.biz.",
    "abc.cde.org.",
    "abc.cde.com..",
  ]
}

resource "google_dns_record_set" "add_ns_records" {
  name = data.google_dns_managed_zone.selected.dns_name
  rrdatas = concat(local.aws_name_servers,data.google_dns_managed_zone.selected.name_servers)
  ttl = 86400
  type = "NS"
  managed_zone = data.google_dns_managed_zone.selected.name

When you have an existing piece of infrastructure that you want to start managing with Terraform, you’ll need to follow the process of importing the existing resources into your Terraform state.

To resolve this, you’ll want to write configuration which represents the current state of your NS record, then use the terraform import command to associate that record with your local Terraform state. Once that’s done, you can update the configuration to your desired state, and terraform plan should show that the resource will be updated.

For details on how to import this particular resource, see the google_dns_record_set documentation.

Hello @alisdair

Thanks a lot for response. Actually there isn’t a existing infra, I am creating that domain as new …

I had the example above with data but when I tried with resources too it fails with same error saying record already exits.

and this problem is only with NS records. I don’t see this issues with aws also aws has allow_overwite to force changes …

  name = "d-mildev-com”
  domain = “mildev.mlp.com”
  visibility = public 
}

locals {
  aws_name_servers = [
    "abc.cde.net.",
    "abc.cde.biz.",
    "abc.cde.org.",
    "abc.cde.com..",
  ]
}

resource "google_dns_record_set" "add_ns_records" {
  name = google_dns_managed_zone.selected.dns_name
  rrdatas = concat(local.aws_name_servers,google_dns_managed_zone.selected.name_servers)
  ttl = 86400
  type = "NS"
  managed_zone = google_dns_managed_zone.selected.name```



Thanks,
Devi

Oh, huh! I see you’ve already filed an issue on the provider, which make sense to me as a next step. If you get a resolution there I’d be interested to hear about it.

1 Like

This i can confirm is bug. I tested with older version of provider like 3.5.0 and it works fine but fails with later versions.

Have raised a issue: Unable to append secondary NS for a domain · Issue #9257 · hashicorp/terraform-provider-google · GitHub

1 Like