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

dereferencing of rg id, name and target update in floating ip #3164

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions ibm/resource_ibm_is_floating_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,16 @@ func resourceIBMISFloatingIP() *schema.Resource {
return nil
}
old, new := diff.GetChange(isFloatingIPTarget)
sess, err := vpcClient(v)
if err != nil {
return err
}
if checkIfZoneChanged(old.(string), new.(string), sess) {
diff.ForceNew(isFloatingIPTarget)
if old != "" || new != "" {
sess, err := vpcClient(v)
if err != nil {
return err
}
if checkIfZoneChanged(old.(string), new.(string), diff.Get(isFloatingIPZone).(string), sess) {
diff.ForceNew(isFloatingIPTarget)
}
}
}

return nil
},
),
Expand Down Expand Up @@ -108,6 +109,7 @@ func resourceIBMISFloatingIP() *schema.Resource {
isFloatingIPTarget: {
Type: schema.TypeString,
Optional: true,
Computed: true,
ConflictsWith: []string{isFloatingIPZone},
Description: "Target info",
},
Expand Down Expand Up @@ -322,8 +324,8 @@ func fipGet(d *schema.ResourceData, meta interface{}, id string) error {
d.Set(ResourceCRN, *floatingip.CRN)
d.Set(ResourceStatus, *floatingip.Status)
if floatingip.ResourceGroup != nil {
d.Set(ResourceGroupName, *floatingip.ResourceGroup.Name)
d.Set(isFloatingIPResourceGroup, *floatingip.ResourceGroup.ID)
d.Set(ResourceGroupName, floatingip.ResourceGroup.Name)
d.Set(isFloatingIPResourceGroup, floatingip.ResourceGroup.ID)
}
return nil
}
Expand Down Expand Up @@ -524,7 +526,7 @@ func isInstanceFloatingIPRefreshFunc(floatingipC *vpcv1.VpcV1, id string) resour
}
}

func checkIfZoneChanged(oldNic, newNic string, floatingipC *vpcv1.VpcV1) bool {
func checkIfZoneChanged(oldNic, newNic, currentZone string, floatingipC *vpcv1.VpcV1) bool {
var oldZone, newZone string
listInstancesOptions := &vpcv1.ListInstancesOptions{}
start := ""
Expand Down Expand Up @@ -556,6 +558,9 @@ func checkIfZoneChanged(oldNic, newNic string, floatingipC *vpcv1.VpcV1) bool {
}
}
if newZone != oldZone {
if oldZone == "" && newZone == currentZone {
return false
}
return true
}
return false
Expand Down