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

DigitalOcean destroy does not handle 404 on droplet #3670

Closed
clstokes opened this issue Oct 28, 2015 · 9 comments · Fixed by #3768
Closed

DigitalOcean destroy does not handle 404 on droplet #3670

clstokes opened this issue Oct 28, 2015 · 9 comments · Fixed by #3768

Comments

@clstokes
Copy link
Contributor

If I create a DigitalOcean droplet with Terraform, then remove the droplet via the DigitalOcean web console, a terraform destroy fails with a 404 error and won't continue. Other Terraform providers seem to handle this case by handling the 404 as a successful destroy and continuing on.

Tested with Terraform v0.6.6.

Terraform config:

provider "digitalocean" {
}

resource "digitalocean_droplet" "example" {
  image  = "ubuntu-14-04-x64"
  name   = "example"
  region = "nyc2"
  size   = "512mb"
}

Abridged Terraform output...

$ terraform apply terraform

digitalocean_droplet.example: Creating...
  image:                "" => "ubuntu-14-04-x64"
  ipv4_address:         "" => "<computed>"
  ipv4_address_private: "" => "<computed>"
  ipv6_address:         "" => "<computed>"
  ipv6_address_private: "" => "<computed>"
  locked:               "" => "<computed>"
  name:                 "" => "example"
  region:               "" => "nyc2"
  size:                 "" => "512mb"
  status:               "" => "<computed>"
digitalocean_droplet.example: Creation complete

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

...

$ 
$ # Droplet removed via DO console
$ 
$ terraform destroy terraform

...

digitalocean_droplet.example: Refreshing state... (ID: 8457342)
Error refreshing state: 1 error(s) occurred:

* digitalocean_droplet.example: Error retrieving droplet: GET https://api.digitalocean.com/v2/droplets/8457342: 404 The resource you were accessing could not be found.
$
@stack72
Copy link
Contributor

stack72 commented Nov 5, 2015

@clstokes this is because the DigitalOceanDropletRead has the following logic

// Retrieve the droplet properties for updating the state
    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" {
            d.SetId("")
            return nil
        }

        return fmt.Errorf("Error retrieving droplet: %s", err)
    }

The string is hard coded and may have changed when we moved to the Official DigitalOcean Goclient

I will submit a PR now to fix this

@clstokes
Copy link
Contributor Author

clstokes commented Nov 5, 2015

@stack72, ah, that makes sense. Is the response code (404) available on the err? It seems that'd be the most future-proof way to fix it, yea?

@stack72
Copy link
Contributor

stack72 commented Nov 5, 2015

@clstokes tried with a string (which was not future proof) and @catsby suggested to use the 404 as well :)

PR is currently re-building

@clstokes
Copy link
Contributor Author

clstokes commented Nov 5, 2015

That Clint is a clever one. 😉

@catsby
Copy link
Contributor

catsby commented Nov 5, 2015

helping

@catsby
Copy link
Contributor

catsby commented Nov 5, 2015

Merged #3768

@omarabid
Copy link

omarabid commented Jan 7, 2016

I'm still getting this error.

@omarabid
Copy link

omarabid commented Jan 7, 2016

Terraform version 0.6.8

@ghost
Copy link

ghost commented Apr 29, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants