Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SOA to root-level record deletion exception #6724

Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions mmv1/third_party/terraform/resources/resource_dns_record_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,22 +336,21 @@ func resourceDnsRecordSetDelete(d *schema.ResourceData, meta interface{}) error

zone := d.Get("managed_zone").(string)

// NS records must always have a value, so we short-circuit delete
// this allows terraform delete to work, but may have unexpected
// side-effects when deleting just that record set.
// Unfortunately, you can set NS records on subdomains, and those
// CAN and MUST be deleted, so we need to retrieve the managed zone,
// check if what we're looking at is a subdomain, and only not delete
// if it's not actually a subdomain
if d.Get("type").(string) == "NS" {
// root-level NS and SOA records must always have some value, so we
// short-ciruit deletes of these. This allows terraform delete to
// work when managing such records.
// NS records on subdomains are not root-level constructs. They
// CAN and MUST be deleted. We check if the NS record set is on a
// subdomain and only really delete when it is.
if d.Get("type").(string) == "NS" || d.Get("type").(string) == "SOA" {
mz, err := config.NewDnsClient(userAgent).ManagedZones.Get(project, zone).Do()
if err != nil {
return fmt.Errorf("Error retrieving managed zone %q from %q: %s", zone, project, err)
}
domain := mz.DnsName

if domain == d.Get("name").(string) {
log.Println("[DEBUG] NS records can't be deleted due to API restrictions, so they're being left in place. See https://www.terraform.io/docs/providers/google/r/dns_record_set.html for more information.")
log.Printf("[DEBUG] root-level %s records can't be deleted due to API restrictions, so they're being left in place. See https://www.terraform.io/docs/providers/google/r/dns_record_set.html for more information.", d.Get("type").(string))
return nil
}
}
Expand Down