Skip to content

Commit c8dfecc

Browse files
author
Brett Mack
committed
Check where nested structs could possibly be nil before trying to access their data
1 parent f140c15 commit c8dfecc

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

builtin/providers/vcd/resource_vcd_network.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,15 @@ func resourceVcdNetworkRead(d *schema.ResourceData, meta interface{}) error {
212212

213213
d.Set("name", network.OrgVDCNetwork.Name)
214214
d.Set("href", network.OrgVDCNetwork.HREF)
215-
d.Set("fence_mode", network.OrgVDCNetwork.Configuration.FenceMode)
216-
d.Set("gateway", network.OrgVDCNetwork.Configuration.IPScopes.IPScope.Gateway)
217-
d.Set("netmask", network.OrgVDCNetwork.Configuration.IPScopes.IPScope.Netmask)
218-
d.Set("dns1", network.OrgVDCNetwork.Configuration.IPScopes.IPScope.DNS1)
219-
d.Set("dns2", network.OrgVDCNetwork.Configuration.IPScopes.IPScope.DNS2)
215+
if c := network.OrgVDCNetwork.Configuration; c != nil {
216+
d.Set("fence_mode", c.FenceMode)
217+
if c.IPScopes != nil {
218+
d.Set("gateway", c.IPScopes.IPScope.Gateway)
219+
d.Set("netmask", c.IPScopes.IPScope.Netmask)
220+
d.Set("dns1", c.IPScopes.IPScope.DNS1)
221+
d.Set("dns2", c.IPScopes.IPScope.DNS2)
222+
}
223+
}
220224

221225
return nil
222226
}

0 commit comments

Comments
 (0)