Skip to content

Commit 2ff49ac

Browse files
committed
Handle import when edge appliance has no switch specs
Such import causes a provider crash as SwitchSpec.Switches can be null (either of). Signed-off-by: Kobi Samoray <[email protected]>
1 parent 2afc2ea commit 2ff49ac

File tree

1 file changed

+37
-35
lines changed

1 file changed

+37
-35
lines changed

nsxt/resource_nsxt_policy_edge_transport_node.go

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,49 +1583,51 @@ func resourceNsxtPolicyEdgeTransportNodeRead(d *schema.ResourceData, m interface
15831583
}
15841584

15851585
var switches []interface{}
1586-
for _, switc := range obj.SwitchSpec.Switches {
1587-
sw := make(map[string]interface{})
1588-
if len(switc.OverlayTransportZonePaths) > 0 {
1589-
sw["overlay_transport_zone_path"] = switc.OverlayTransportZonePaths[0]
1590-
}
1591-
1592-
var pnics []interface{}
1593-
for _, pnic := range switc.Pnics {
1594-
p := make(map[string]interface{})
1595-
if pnic.DatapathNetworkId != nil {
1596-
p["datapath_network_id"] = pnic.DatapathNetworkId
1586+
if obj.SwitchSpec != nil && obj.SwitchSpec.Switches != nil {
1587+
for _, switc := range obj.SwitchSpec.Switches {
1588+
sw := make(map[string]interface{})
1589+
if len(switc.OverlayTransportZonePaths) > 0 {
1590+
sw["overlay_transport_zone_path"] = switc.OverlayTransportZonePaths[0]
15971591
}
1598-
p["device_name"] = pnic.DeviceName
1599-
p["uplink_name"] = pnic.UplinkName
16001592

1601-
pnics = append(pnics, p)
1602-
}
1603-
sw["pnic"] = pnics
1593+
var pnics []interface{}
1594+
for _, pnic := range switc.Pnics {
1595+
p := make(map[string]interface{})
1596+
if pnic.DatapathNetworkId != nil {
1597+
p["datapath_network_id"] = pnic.DatapathNetworkId
1598+
}
1599+
p["device_name"] = pnic.DeviceName
1600+
p["uplink_name"] = pnic.UplinkName
16041601

1605-
for _, pp := range switc.ProfilePaths {
1606-
if *pp.Key == model.PolicyEdgeTransportNodeSwitchProfileTypePathEntry_KEY_UPLINKHOSTSWITCHPROFILE {
1607-
sw["uplink_host_switch_profile_path"] = pp.Value
1608-
} else if *pp.Key == model.PolicyEdgeTransportNodeSwitchProfileTypePathEntry_KEY_LLDPHOSTSWITCHPROFILE {
1609-
sw["lldp_host_switch_profile_path"] = pp.Value
1602+
pnics = append(pnics, p)
16101603
}
1611-
}
1604+
sw["pnic"] = pnics
16121605

1613-
sw["switch_name"] = switc.SwitchName
1614-
var tunnelEndpoints []interface{}
1615-
for _, tep := range switc.TunnelEndpoints {
1616-
t := make(map[string]interface{})
1617-
t["ip_assignment"], err = setPolicyIPAssignmentsInSchema(tep.IpAssignmentSpecs)
1618-
if err != nil {
1619-
return err
1606+
for _, pp := range switc.ProfilePaths {
1607+
if *pp.Key == model.PolicyEdgeTransportNodeSwitchProfileTypePathEntry_KEY_UPLINKHOSTSWITCHPROFILE {
1608+
sw["uplink_host_switch_profile_path"] = pp.Value
1609+
} else if *pp.Key == model.PolicyEdgeTransportNodeSwitchProfileTypePathEntry_KEY_LLDPHOSTSWITCHPROFILE {
1610+
sw["lldp_host_switch_profile_path"] = pp.Value
1611+
}
16201612
}
1621-
t["vlan"] = tep.Vlan
16221613

1623-
tunnelEndpoints = append(tunnelEndpoints, t)
1624-
}
1625-
sw["tunnel_endpoint"] = tunnelEndpoints
1626-
d.Set("vlan_transport_zone_paths", switc.VlanTransportZonePaths)
1614+
sw["switch_name"] = switc.SwitchName
1615+
var tunnelEndpoints []interface{}
1616+
for _, tep := range switc.TunnelEndpoints {
1617+
t := make(map[string]interface{})
1618+
t["ip_assignment"], err = setPolicyIPAssignmentsInSchema(tep.IpAssignmentSpecs)
1619+
if err != nil {
1620+
return err
1621+
}
1622+
t["vlan"] = tep.Vlan
16271623

1628-
switches = append(switches, sw)
1624+
tunnelEndpoints = append(tunnelEndpoints, t)
1625+
}
1626+
sw["tunnel_endpoint"] = tunnelEndpoints
1627+
d.Set("vlan_transport_zone_paths", switc.VlanTransportZonePaths)
1628+
1629+
switches = append(switches, sw)
1630+
}
16291631
}
16301632
d.Set("switch", switches)
16311633

0 commit comments

Comments
 (0)