Add nil checks

Signed-off-by: darshanime <deathbullet@gmail.com>
This commit is contained in:
darshanime 2021-07-28 19:23:17 +05:30
parent c8a2ffdb72
commit 898afa2fd9
1 changed files with 12 additions and 2 deletions

View File

@ -452,6 +452,7 @@ func mapFromVM(vm compute.VirtualMachine) virtualMachine {
osType := string(vm.StorageProfile.OsDisk.OsType)
tags := map[string]*string{}
networkInterfaces := []string{}
var computerName string
if vm.Tags != nil {
tags = vm.Tags
@ -463,10 +464,14 @@ func mapFromVM(vm compute.VirtualMachine) virtualMachine {
}
}
if vm.VirtualMachineProperties != nil && vm.VirtualMachineProperties.OsProfile != nil {
computerName = *(vm.VirtualMachineProperties.OsProfile.ComputerName)
}
return virtualMachine{
ID: *(vm.ID),
Name: *(vm.Name),
ComputerName: *(vm.VirtualMachineProperties.OsProfile.ComputerName),
ComputerName: computerName,
Type: *(vm.Type),
Location: *(vm.Location),
OsType: osType,
@ -480,6 +485,7 @@ func mapFromVMScaleSetVM(vm compute.VirtualMachineScaleSetVM, scaleSetName strin
osType := string(vm.StorageProfile.OsDisk.OsType)
tags := map[string]*string{}
networkInterfaces := []string{}
var computerName string
if vm.Tags != nil {
tags = vm.Tags
@ -491,10 +497,14 @@ func mapFromVMScaleSetVM(vm compute.VirtualMachineScaleSetVM, scaleSetName strin
}
}
if vm.VirtualMachineScaleSetVMProperties != nil && vm.VirtualMachineScaleSetVMProperties.OsProfile != nil {
computerName = *(vm.VirtualMachineScaleSetVMProperties.OsProfile.ComputerName)
}
return virtualMachine{
ID: *(vm.ID),
Name: *(vm.Name),
ComputerName: *(vm.VirtualMachineScaleSetVMProperties.OsProfile.ComputerName),
ComputerName: computerName,
Type: *(vm.Type),
Location: *(vm.Location),
OsType: osType,