Skip to content

Commit

Permalink
FloatingIPV2: unset ID on 404 HTTP status code
Browse files Browse the repository at this point in the history
Unset ID on 404 HTTP response status code.
  • Loading branch information
ozerovandrei committed Nov 7, 2018
1 parent 86290ab commit 9d5347a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions selvpc/resource_selvpc_resell_floatingip_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"log"
"net/http"

"github.com/hashicorp/terraform/helper/schema"
"github.com/selectel/go-selvpcclient/selvpcclient/resell/v2/floatingips"
Expand Down Expand Up @@ -105,8 +106,13 @@ func resourceResellFloatingIPV2Read(d *schema.ResourceData, meta interface{}) er
ctx := context.Background()

log.Printf("[DEBUG] Getting floating ip %s", d.Id())
floatingIP, _, err := floatingips.Get(ctx, resellV2Client, d.Id())
floatingIP, response, err := floatingips.Get(ctx, resellV2Client, d.Id())
if err != nil {
if response.StatusCode == http.StatusNotFound {
d.SetId("")
return nil
}

return err
}

Expand All @@ -131,8 +137,13 @@ func resourceResellFloatingIPV2Delete(d *schema.ResourceData, meta interface{})
ctx := context.Background()

log.Printf("[DEBUG] Deleting floating ip %s\n", d.Id())
_, err := floatingips.Delete(ctx, resellV2Client, d.Id())
response, err := floatingips.Delete(ctx, resellV2Client, d.Id())
if err != nil {
if response.StatusCode == http.StatusNotFound {
d.SetId("")
return nil
}

return err
}

Expand Down

0 comments on commit 9d5347a

Please sign in to comment.