Check where nested structs could possibly be nil before trying to access their data

This commit is contained in:
Brett Mack 2015-11-17 11:40:37 +00:00
parent f140c15039
commit c8dfecc65f
1 changed files with 9 additions and 5 deletions

View File

@ -212,11 +212,15 @@ func resourceVcdNetworkRead(d *schema.ResourceData, meta interface{}) error {
d.Set("name", network.OrgVDCNetwork.Name) d.Set("name", network.OrgVDCNetwork.Name)
d.Set("href", network.OrgVDCNetwork.HREF) d.Set("href", network.OrgVDCNetwork.HREF)
d.Set("fence_mode", network.OrgVDCNetwork.Configuration.FenceMode) if c := network.OrgVDCNetwork.Configuration; c != nil {
d.Set("gateway", network.OrgVDCNetwork.Configuration.IPScopes.IPScope.Gateway) d.Set("fence_mode", c.FenceMode)
d.Set("netmask", network.OrgVDCNetwork.Configuration.IPScopes.IPScope.Netmask) if c.IPScopes != nil {
d.Set("dns1", network.OrgVDCNetwork.Configuration.IPScopes.IPScope.DNS1) d.Set("gateway", c.IPScopes.IPScope.Gateway)
d.Set("dns2", network.OrgVDCNetwork.Configuration.IPScopes.IPScope.DNS2) d.Set("netmask", c.IPScopes.IPScope.Netmask)
d.Set("dns1", c.IPScopes.IPScope.DNS1)
d.Set("dns2", c.IPScopes.IPScope.DNS2)
}
}
return nil return nil
} }