Skip to content

Commit

Permalink
Merge pull request #5365 from jtopjian/openstack-instance-network-upd…
Browse files Browse the repository at this point in the history
…ate-guard

provider/openstack: Safely typecast network during instance update
  • Loading branch information
jtopjian committed Feb 28, 2016
2 parents 9fade4d + d82a4c9 commit ba8033b
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -654,16 +654,23 @@ func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) e
oldNetworkList := oldNetworks.([]interface{})
newNetworkList := newNetworks.([]interface{})
for i, oldNet := range oldNetworkList {
oldNetRaw := oldNet.(map[string]interface{})
oldFIP := oldNetRaw["floating_ip"].(string)
oldFixedIP := oldNetRaw["fixed_ip_v4"].(string)
var oldFIP, newFIP string
var oldFixedIP, newFixedIP string

newNetRaw := newNetworkList[i].(map[string]interface{})
newFIP := newNetRaw["floating_ip"].(string)
newFixedIP := newNetRaw["fixed_ip_v4"].(string)
if oldNetRaw, ok := oldNet.(map[string]interface{}); ok {
oldFIP = oldNetRaw["floating_ip"].(string)
oldFixedIP = oldNetRaw["fixed_ip_v4"].(string)
}

if len(newNetworkList) > i {
if newNetRaw, ok := newNetworkList[i].(map[string]interface{}); ok {
newFIP = newNetRaw["floating_ip"].(string)
newFixedIP = newNetRaw["fixed_ip_v4"].(string)
}
}

// Only changes to the floating IP are supported
if oldFIP != newFIP {
if oldFIP != "" && newFIP != "" && oldFIP != newFIP {
log.Printf("[DEBUG] Attempting to disassociate %s from %s", oldFIP, d.Id())
if err := disassociateFloatingIPFromInstance(computeClient, oldFIP, d.Id(), oldFixedIP); err != nil {
return fmt.Errorf("Error disassociating Floating IP during update: %s", err)
Expand Down

0 comments on commit ba8033b

Please sign in to comment.