Skip to content

Commit

Permalink
unassign floating IP prior to removal
Browse files Browse the repository at this point in the history
  • Loading branch information
0x4c6565 committed Oct 20, 2021
1 parent 8288041 commit 4ef4be4
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion ecloud/resource_instance.go
Expand Up @@ -537,9 +537,31 @@ func resourceInstanceDelete(d *schema.ResourceData, meta interface{}) error {
//remove floating ip if set
if len(d.Get("floating_ip_id").(string)) > 1 {
fip := d.Get("floating_ip_id").(string)

log.Printf("[DEBUG] Unassigning floating ip with ID [%s]", fip)

taskID, err := service.UnassignFloatingIP(fip)
if err != nil {
switch err.(type) {
case *ecloudservice.FloatingIPNotFoundError:
log.Printf("[DEBUG] Floating IP with ID [%s] not found. Skipping unassign.", fip)
default:
return fmt.Errorf("Error unassigning floating ip with ID [%s]: %s", fip, err)
}
}

_, err = waitForResourceState(
ecloudservice.TaskStatusComplete.String(),
TaskStatusRefreshFunc(service, taskID),
d.Timeout(schema.TimeoutDelete),
)
if err != nil {
return fmt.Errorf("Error waiting for floating ip with ID [%s] to be unassigned: %w", d.Id(), err)
}

log.Printf("[DEBUG] Removing floating ip with ID [%s]", fip)

taskID, err := service.DeleteFloatingIP(fip)
taskID, err = service.DeleteFloatingIP(fip)
if err != nil {
switch err.(type) {
case *ecloudservice.FloatingIPNotFoundError:
Expand Down

0 comments on commit 4ef4be4

Please sign in to comment.