Handle missing floating IPs (#55)

This commit is contained in:
Arve Knudsen 2018-06-27 21:26:03 +02:00 committed by Andrew Starr-Bochicchio
parent 5dd3a6781c
commit 1c0e1d5b0f
1 changed files with 16 additions and 12 deletions

View File

@ -117,7 +117,8 @@ func resourceDigitalOceanFloatingIpRead(d *schema.ResourceData, meta interface{}
client := meta.(*godo.Client)
log.Printf("[INFO] Reading the details of the FloatingIP %s", d.Id())
floatingIp, _, err := client.FloatingIPs.Get(context.Background(), d.Id())
floatingIp, resp, err := client.FloatingIPs.Get(context.Background(), d.Id())
if resp.StatusCode != 404 {
if err != nil {
return fmt.Errorf("Error retrieving FloatingIP: %s", err)
}
@ -132,6 +133,9 @@ func resourceDigitalOceanFloatingIpRead(d *schema.ResourceData, meta interface{}
}
d.Set("ip_address", floatingIp.IP)
} else {
d.SetId("")
}
return nil
}