From 53f02fc4a2a53cfdacc565bf136c39686e812b4a Mon Sep 17 00:00:00 2001 From: Alex Berghage Date: Sun, 6 Dec 2015 06:52:35 -0500 Subject: [PATCH] Analogous to #3768 -- just for DNS and keys. The error string for 404s on DNS domains has (apparently) changed, causing things to be a little sad when you modify DNS domains from the DO console instead of terraform. This is just the same fix as was applied to droplets around this time last month. While I was at it I just fixed this everywhere I saw it in the DO provider source tree. --- .../digitalocean/resource_digitalocean_domain.go | 5 ++--- .../digitalocean/resource_digitalocean_record.go | 12 ++++++------ .../digitalocean/resource_digitalocean_ssh_key.go | 5 ++--- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/builtin/providers/digitalocean/resource_digitalocean_domain.go b/builtin/providers/digitalocean/resource_digitalocean_domain.go index d7c4edca1..657acb21d 100644 --- a/builtin/providers/digitalocean/resource_digitalocean_domain.go +++ b/builtin/providers/digitalocean/resource_digitalocean_domain.go @@ -3,7 +3,6 @@ package digitalocean import ( "fmt" "log" - "strings" "github.com/digitalocean/godo" "github.com/hashicorp/terraform/helper/schema" @@ -56,11 +55,11 @@ func resourceDigitalOceanDomainCreate(d *schema.ResourceData, meta interface{}) func resourceDigitalOceanDomainRead(d *schema.ResourceData, meta interface{}) error { client := meta.(*godo.Client) - domain, _, err := client.Domains.Get(d.Id()) + domain, resp, err := client.Domains.Get(d.Id()) if err != nil { // If the domain is somehow already destroyed, mark as // successfully gone - if strings.Contains(err.Error(), "404 Not Found") { + if resp.StatusCode == 404 { d.SetId("") return nil } diff --git a/builtin/providers/digitalocean/resource_digitalocean_record.go b/builtin/providers/digitalocean/resource_digitalocean_record.go index ebcb2e0f8..1db6084bd 100644 --- a/builtin/providers/digitalocean/resource_digitalocean_record.go +++ b/builtin/providers/digitalocean/resource_digitalocean_record.go @@ -115,11 +115,11 @@ func resourceDigitalOceanRecordRead(d *schema.ResourceData, meta interface{}) er return fmt.Errorf("invalid record ID: %v", err) } - rec, _, err := client.Domains.Record(domain, id) + rec, resp, err := client.Domains.Record(domain, id) if err != nil { // If the record is somehow already destroyed, mark as // successfully gone - if strings.Contains(err.Error(), "404 Not Found") { + if resp.StatusCode == 404 { d.SetId("") return nil } @@ -183,15 +183,15 @@ func resourceDigitalOceanRecordDelete(d *schema.ResourceData, meta interface{}) log.Printf("[INFO] Deleting record: %s, %d", domain, id) - _, err = client.Domains.DeleteRecord(domain, id) - if err != nil { + resp, delErr := client.Domains.DeleteRecord(domain, id) + if delErr != nil { // If the record is somehow already destroyed, mark as // successfully gone - if strings.Contains(err.Error(), "404 Not Found") { + if resp.StatusCode == 404 { return nil } - return fmt.Errorf("Error deleting record: %s", err) + return fmt.Errorf("Error deleting record: %s", delErr) } return nil diff --git a/builtin/providers/digitalocean/resource_digitalocean_ssh_key.go b/builtin/providers/digitalocean/resource_digitalocean_ssh_key.go index d6eb96f09..79614f599 100644 --- a/builtin/providers/digitalocean/resource_digitalocean_ssh_key.go +++ b/builtin/providers/digitalocean/resource_digitalocean_ssh_key.go @@ -4,7 +4,6 @@ import ( "fmt" "log" "strconv" - "strings" "github.com/digitalocean/godo" "github.com/hashicorp/terraform/helper/schema" @@ -71,11 +70,11 @@ func resourceDigitalOceanSSHKeyRead(d *schema.ResourceData, meta interface{}) er return fmt.Errorf("invalid SSH key id: %v", err) } - key, _, err := client.Keys.GetByID(id) + key, resp, err := client.Keys.GetByID(id) if err != nil { // If the key is somehow already destroyed, mark as // successfully gone - if strings.Contains(err.Error(), "404 Not Found") { + if resp.StatusCode == 404 { d.SetId("") return nil }