From 032a42797ea8b41bc29cade1223716284259f30b Mon Sep 17 00:00:00 2001 From: stack72 Date: Thu, 5 Nov 2015 15:01:07 +0000 Subject: [PATCH 1/3] Fixing the DigitalOcean Droplet 404 potential on refresh of state --- builtin/providers/digitalocean/resource_digitalocean_droplet.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/providers/digitalocean/resource_digitalocean_droplet.go b/builtin/providers/digitalocean/resource_digitalocean_droplet.go index ef25b0074..decf94476 100644 --- a/builtin/providers/digitalocean/resource_digitalocean_droplet.go +++ b/builtin/providers/digitalocean/resource_digitalocean_droplet.go @@ -189,7 +189,7 @@ func resourceDigitalOceanDropletRead(d *schema.ResourceData, meta interface{}) e droplet, _, err := client.Droplets.Get(id) if err != nil { // check if the droplet no longer exists. - if err.Error() == "Error retrieving droplet: API Error: 404 Not Found" { + if strings.Contains(err.Error(), "404 The resource you were accessing could not be found") { d.SetId("") return nil } From 2504cb46246d7cac8ce9d1f08fb002337b1fedbc Mon Sep 17 00:00:00 2001 From: stack72 Date: Thu, 5 Nov 2015 16:33:29 +0000 Subject: [PATCH 2/3] Changing the DigitalOcean Droplet 404 from a message string to an actual 404 status code --- .../providers/digitalocean/resource_digitalocean_droplet.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/providers/digitalocean/resource_digitalocean_droplet.go b/builtin/providers/digitalocean/resource_digitalocean_droplet.go index decf94476..a4f80015b 100644 --- a/builtin/providers/digitalocean/resource_digitalocean_droplet.go +++ b/builtin/providers/digitalocean/resource_digitalocean_droplet.go @@ -186,10 +186,10 @@ func resourceDigitalOceanDropletRead(d *schema.ResourceData, meta interface{}) e } // Retrieve the droplet properties for updating the state - droplet, _, err := client.Droplets.Get(id) + droplet, resp, err := client.Droplets.Get(id) if err != nil { // check if the droplet no longer exists. - if strings.Contains(err.Error(), "404 The resource you were accessing could not be found") { + if resp.StatusCode == 404 { d.SetId("") return nil } From 6a811e2e4f075b645249ecfb2512e0266b602e8e Mon Sep 17 00:00:00 2001 From: stack72 Date: Thu, 5 Nov 2015 17:32:57 +0000 Subject: [PATCH 3/3] Logging that the DO droplet wasn't found before removing it --- builtin/providers/digitalocean/resource_digitalocean_droplet.go | 1 + 1 file changed, 1 insertion(+) diff --git a/builtin/providers/digitalocean/resource_digitalocean_droplet.go b/builtin/providers/digitalocean/resource_digitalocean_droplet.go index a4f80015b..050577854 100644 --- a/builtin/providers/digitalocean/resource_digitalocean_droplet.go +++ b/builtin/providers/digitalocean/resource_digitalocean_droplet.go @@ -190,6 +190,7 @@ func resourceDigitalOceanDropletRead(d *schema.ResourceData, meta interface{}) e if err != nil { // check if the droplet no longer exists. if resp.StatusCode == 404 { + log.Printf("[WARN] DigitalOcean Droplet (%s) not found", d.Id()) d.SetId("") return nil }