Skip to content

Commit

Permalink
fix(bm-nic): added check for 0.0.0.0 reserved ip on nic availability (#…
Browse files Browse the repository at this point in the history
…4122)

* fix(bm-nic): added check for 0.0.0.0 reserved ip on nic availability

* fixed floating ip details(deprecated reserved_ip attribute) in bare metal server nic
  • Loading branch information
ujjwal-ibm authored Oct 25, 2022
1 parent 10357eb commit a7b49a5
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
const (
isBareMetalServerNicEnableInfraNAT = "enable_infrastructure_nat"
isBareMetalServerNicFloatingIPs = "floating_ips"
isBareMetalServerNicFloatingIPId = "id"
isBareMetalServerNicIpAddress = "address"
isBareMetalServerNicIpCRN = "crn"
isBareMetalServerNicIpHref = "href"
Expand Down Expand Up @@ -91,8 +92,15 @@ func DataSourceIBMIsBareMetalServerNetworkInterface() *schema.Resource {
isBareMetalServerNicIpID: {
Type: schema.TypeString,
Computed: true,
Deprecated: "This field is deprecated - replaced by id",
Description: "The unique identifier for this floating IP",
},
isBareMetalServerNicFloatingIPId: {
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier for this floating IP",
},

isBareMetalServerNicIpName: {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -243,8 +251,9 @@ func dataSourceIBMISBareMetalServerNetworkInterfaceRead(context context.Context,
if nic.FloatingIps != nil {
for _, ip := range nic.FloatingIps {
currentIP := map[string]interface{}{
isBareMetalServerNicIpID: *ip.ID,
isBareMetalServerNicIpAddress: *ip.Address,
isBareMetalServerNicIpID: *ip.ID,
isBareMetalServerNicFloatingIPId: *ip.ID,
isBareMetalServerNicIpAddress: *ip.Address,
}
floatingIPList = append(floatingIPList, currentIP)
}
Expand Down Expand Up @@ -316,8 +325,9 @@ func dataSourceIBMISBareMetalServerNetworkInterfaceRead(context context.Context,
if nic.FloatingIps != nil {
for _, ip := range nic.FloatingIps {
currentIP := map[string]interface{}{
isBareMetalServerNicIpID: *ip.ID,
isBareMetalServerNicIpAddress: *ip.Address,
isBareMetalServerNicIpID: *ip.ID,
isBareMetalServerNicFloatingIPId: *ip.ID,
isBareMetalServerNicIpAddress: *ip.Address,
}
floatingIPList = append(floatingIPList, currentIP)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ func DataSourceIBMIsBareMetalServerNetworkInterfaces() *schema.Resource {
Description: "The URL for this floating IP",
},
isBareMetalServerNicIpID: {
Type: schema.TypeString,
Computed: true,
Deprecated: "This field is deprecated - replaced by id",
Description: "The unique identifier for this floating IP",
},
isBareMetalServerNicFloatingIPId: {
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier for this floating IP",
Expand Down Expand Up @@ -231,8 +237,9 @@ func dataSourceIBMISBareMetalServerNetworkInterfacesRead(context context.Context
floatingIPList := make([]map[string]interface{}, 0)
for _, ip := range nic.FloatingIps {
currentIP := map[string]interface{}{
isBareMetalServerNicIpID: *ip.ID,
isBareMetalServerNicIpAddress: *ip.Address,
isBareMetalServerNicIpID: *ip.ID,
isBareMetalServerNicFloatingIPId: *ip.ID,
isBareMetalServerNicIpAddress: *ip.Address,
}
floatingIPList = append(floatingIPList, currentIP)
}
Expand Down Expand Up @@ -297,8 +304,9 @@ func dataSourceIBMISBareMetalServerNetworkInterfacesRead(context context.Context
floatingIPList := make([]map[string]interface{}, 0)
for _, ip := range nic.FloatingIps {
currentIP := map[string]interface{}{
isBareMetalServerNicIpID: *ip.ID,
isBareMetalServerNicIpAddress: *ip.Address,
isBareMetalServerNicIpID: *ip.ID,
isBareMetalServerNicFloatingIPId: *ip.ID,
isBareMetalServerNicIpAddress: *ip.Address,
}
floatingIPList = append(floatingIPList, currentIP)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ func ResourceIBMIsBareMetalServerNetworkInterface() *schema.Resource {
Computed: true,
Description: "The globally unique IP address",
},
isBareMetalServerNicFloatingIPId: {
Type: schema.TypeString,
Computed: true,
Description: "The globally unique IP identifier",
},
},
},
},
Expand Down Expand Up @@ -403,12 +408,12 @@ func resourceIBMISBareMetalServerNetworkInterfaceCreate(context context.Context,
}

log.Printf("[INFO] Bare Metal Server Network Interface : %s", d.Id())
_, err = isWaitForBareMetalServerNetworkInterfaceAvailable(sess, bareMetalServerId, nicId, d.Timeout(schema.TimeoutCreate), d)
nicAfterWait, err := isWaitForBareMetalServerNetworkInterfaceAvailable(sess, bareMetalServerId, nicId, d.Timeout(schema.TimeoutCreate), d)
if err != nil {
return diag.FromErr(err)
}

err = bareMetalServerNICGet(d, meta, sess, nic, bareMetalServerId)
err = bareMetalServerNICGet(d, meta, sess, nicAfterWait, bareMetalServerId)
if err != nil {
return diag.FromErr(err)
}
Expand Down Expand Up @@ -543,16 +548,16 @@ func createVlanTypeNetworkInterface(context context.Context, d *schema.ResourceD
}
}

err = bareMetalServerNICGet(d, meta, sess, nic, bareMetalServerId)
_, nicId, err := ParseNICTerraformID(d.Id())
if err != nil {
return err
}
_, nicId, err := ParseNICTerraformID(d.Id())
log.Printf("[INFO] Bare Metal Server Network Interface : %s", d.Id())
nicAfterWait, err := isWaitForBareMetalServerNetworkInterfaceAvailable(sess, bareMetalServerId, nicId, d.Timeout(schema.TimeoutCreate), d)
if err != nil {
return err
}
log.Printf("[INFO] Bare Metal Server Network Interface : %s", d.Id())
_, err = isWaitForBareMetalServerNetworkInterfaceAvailable(sess, bareMetalServerId, nicId, d.Timeout(schema.TimeoutCreate), d)
err = bareMetalServerNICGet(d, meta, sess, nicAfterWait, bareMetalServerId)
if err != nil {
return err
}
Expand Down Expand Up @@ -602,8 +607,8 @@ func bareMetalServerNICGet(d *schema.ResourceData, meta interface{}, sess *vpcv1
if nic.FloatingIps != nil {
for _, ip := range nic.FloatingIps {
currentIP := map[string]interface{}{
isBareMetalServerNicIpID: *ip.ID,
isBareMetalServerNicIpAddress: *ip.Address,
isBareMetalServerNicFloatingIPId: *ip.ID,
isBareMetalServerNicIpAddress: *ip.Address,
}
floatingIPList = append(floatingIPList, currentIP)
}
Expand Down Expand Up @@ -680,8 +685,8 @@ func bareMetalServerNICGet(d *schema.ResourceData, meta interface{}, sess *vpcv1
if nic.FloatingIps != nil {
for _, ip := range nic.FloatingIps {
currentIP := map[string]interface{}{
isBareMetalServerNicIpID: *ip.ID,
isBareMetalServerNicIpAddress: *ip.Address,
isBareMetalServerNicFloatingIPId: *ip.ID,
isBareMetalServerNicIpAddress: *ip.Address,
}
floatingIPList = append(floatingIPList, currentIP)
}
Expand Down Expand Up @@ -1046,6 +1051,9 @@ func isBareMetalServerNetworkInterfaceRefreshFunc(client *vpcv1.VpcV1, bareMetal
nic := bmsNic.(*vpcv1.BareMetalServerNetworkInterfaceByVlan)
status = *nic.Status
d.Set(isBareMetalServerNicStatus, *nic.Status)
if *nic.PrimaryIP.Address == "0.0.0.0" {
return bmsNic, "pending", nil
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ func ResourceIBMIsBareMetalServerNetworkInterfaceAllowFloat() *schema.Resource {
Computed: true,
Description: "The globally unique IP address",
},
isBareMetalServerNicFloatingIPId: {
Type: schema.TypeString,
Computed: true,
Description: "The globally unique IP identifier",
},
},
},
},
Expand Down Expand Up @@ -324,12 +329,12 @@ func createVlanTypeNetworkInterfaceAllowFloat(context context.Context, d *schema
}

log.Printf("[INFO] Bare Metal Server Network Interface : %s", d.Id())
_, err = isWaitForBareMetalServerNetworkInterfaceAvailable(sess, bareMetalServerId, nicId, d.Timeout(schema.TimeoutCreate), d)
nicAfterWait, err := isWaitForBareMetalServerNetworkInterfaceAvailable(sess, bareMetalServerId, nicId, d.Timeout(schema.TimeoutCreate), d)
if err != nil {
return err
}

err = bareMetalServerNICAllowFloatGet(d, meta, sess, nic, bareMetalServerId)
err = bareMetalServerNICAllowFloatGet(d, meta, sess, nicAfterWait, bareMetalServerId)
if err != nil {
return err
}
Expand Down Expand Up @@ -429,8 +434,8 @@ func bareMetalServerNICAllowFloatGet(d *schema.ResourceData, meta interface{}, s
if nic.FloatingIps != nil {
for _, ip := range nic.FloatingIps {
currentIP := map[string]interface{}{
isBareMetalServerNicIpID: *ip.ID,
isBareMetalServerNicIpAddress: *ip.Address,
isBareMetalServerNicFloatingIPId: *ip.ID,
isBareMetalServerNicIpAddress: *ip.Address,
}
floatingIPList = append(floatingIPList, currentIP)
}
Expand Down Expand Up @@ -502,8 +507,8 @@ func bareMetalServerNICAllowFloatGet(d *schema.ResourceData, meta interface{}, s
if nic.FloatingIps != nil {
for _, ip := range nic.FloatingIps {
currentIP := map[string]interface{}{
isBareMetalServerNicIpID: *ip.ID,
isBareMetalServerNicIpAddress: *ip.Address,
isBareMetalServerNicFloatingIPId: *ip.ID,
isBareMetalServerNicIpAddress: *ip.Address,
}
floatingIPList = append(floatingIPList, currentIP)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVE
return nil
}),
resource.TestCheckResourceAttrSet(
"ibm_is_bare_metal_server.testacc_bms", "floating_bare_metal_server"),
"ibm_is_bare_metal_server_network_interface_allow_float.bms_nic", "floating_bare_metal_server"),
resource.TestCheckResourceAttrWith("ibm_is_bare_metal_server_network_interface_allow_float.bms_nic", "floating_bare_metal_server", func(v string) error {
if v == "" {
return fmt.Errorf("Attribute 'floating_bare_metal_server' %s is not populated", v)
Expand Down Expand Up @@ -108,7 +108,7 @@ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVE
return nil
}),
resource.TestCheckResourceAttrSet(
"ibm_is_bare_metal_server.testacc_bms", "floating_bare_metal_server"),
"ibm_is_bare_metal_server_network_interface_allow_float.bms_nic", "floating_bare_metal_server"),
resource.TestCheckResourceAttrWith("ibm_is_bare_metal_server_network_interface_allow_float.bms_nic", "floating_bare_metal_server", func(v string) error {
if v == "" {
return fmt.Errorf("Attribute 'floating_bare_metal_server' %s is not populated", v)
Expand Down

0 comments on commit a7b49a5

Please sign in to comment.