Skip to content

Commit

Permalink
fix: dhcp source crash on nil network
Browse files Browse the repository at this point in the history
Fixes IBM-Cloud#3951

Signed-off-by: Yussuf Shaikh <yussuf.shaikh1@ibm.com>
  • Loading branch information
yussufsh committed Aug 6, 2022
1 parent 3b78b34 commit 4a6257a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
11 changes: 8 additions & 3 deletions ibm/service/power/data_source_ibm_pi_dhcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,15 @@ func dataSourceIBMPIDhcpRead(ctx context.Context, d *schema.ResourceData, meta i
// set attributes
d.SetId(fmt.Sprintf("%s/%s", cloudInstanceID, *dhcpServer.ID))
d.Set(Attr_DhcpID, *dhcpServer.ID)
d.Set(Attr_DhcpNetworkDeprecated, *dhcpServer.Network.ID)
d.Set(Attr_DhcpNetworkID, *dhcpServer.Network.ID)
d.Set(Attr_DhcpNetworkName, *dhcpServer.Network.Name)
d.Set(Attr_DhcpStatus, *dhcpServer.Status)

if dhcpServer.Network != nil {
dhcpNetwork := dhcpServer.Network
d.Set(Attr_DhcpNetworkDeprecated, *dhcpNetwork.ID)
d.Set(Attr_DhcpNetworkID, *dhcpNetwork.ID)
d.Set(Attr_DhcpNetworkName, *dhcpNetwork.Name)
}

if dhcpServer.Leases != nil {
leaseList := make([]map[string]string, len(dhcpServer.Leases))
for i, lease := range dhcpServer.Leases {
Expand Down
13 changes: 8 additions & 5 deletions ibm/service/power/data_source_ibm_pi_dhcps.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,14 @@ func dataSourceIBMPIDhcpServersRead(ctx context.Context, d *schema.ResourceData,
servers := make([]map[string]interface{}, 0, len(dhcpServers))
for _, dhcpServer := range dhcpServers {
server := map[string]interface{}{
Attr_DhcpID: *dhcpServer.ID,
Attr_DhcpNetworkDeprecated: *dhcpServer.Network.ID,
Attr_DhcpNetworkID: *dhcpServer.Network.ID,
Attr_DhcpNetworkName: *dhcpServer.Network.Name,
Attr_DhcpStatus: *dhcpServer.Status,
Attr_DhcpID: *dhcpServer.ID,
Attr_DhcpStatus: *dhcpServer.Status,
}
if dhcpServer.Network != nil {
dhcpNetwork := dhcpServer.Network
server[Attr_DhcpNetworkDeprecated] = *dhcpNetwork.ID
server[Attr_DhcpNetworkID] = *dhcpNetwork.ID
server[Attr_DhcpNetworkName] = *dhcpNetwork.Name
}
servers = append(servers, server)
}
Expand Down
11 changes: 8 additions & 3 deletions ibm/service/power/resource_ibm_pi_dhcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,15 @@ func resourceIBMPIDhcpRead(ctx context.Context, d *schema.ResourceData, meta int
// set attributes
d.SetId(fmt.Sprintf("%s/%s", cloudInstanceID, *dhcpServer.ID))
d.Set(Attr_DhcpID, *dhcpServer.ID)
d.Set(Attr_DhcpNetworkDeprecated, *dhcpServer.Network.ID)
d.Set(Attr_DhcpNetworkID, *dhcpServer.Network.ID)
d.Set(Attr_DhcpNetworkName, *dhcpServer.Network.Name)
d.Set(Attr_DhcpStatus, *dhcpServer.Status)

if dhcpServer.Network != nil {
dhcpNetwork := dhcpServer.Network
d.Set(Attr_DhcpNetworkDeprecated, *dhcpNetwork.ID)
d.Set(Attr_DhcpNetworkID, *dhcpNetwork.ID)
d.Set(Attr_DhcpNetworkName, *dhcpNetwork.Name)
}

if dhcpServer.Leases != nil {
leaseList := make([]map[string]string, len(dhcpServer.Leases))
for i, lease := range dhcpServer.Leases {
Expand Down

0 comments on commit 4a6257a

Please sign in to comment.