Skip to content

Commit

Permalink
Handling disk.ManagedDisk.ID being nil (#1947)
Browse files Browse the repository at this point in the history
  • Loading branch information
tombuildsstuff authored Sep 19, 2018
1 parent 4df1a85 commit 3bfc46e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion azurerm/resource_arm_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ func flattenAzureRmImageDataDisks(diskImages *[]compute.ImageDataDisk) []interfa
l["size_gb"] = *disk.DiskSizeGB
}
l["lun"] = *disk.Lun
if disk.ManagedDisk != nil {
if disk.ManagedDisk != nil && disk.ManagedDisk.ID != nil {
l["managed_disk_id"] = *disk.ManagedDisk.ID
}

Expand Down
16 changes: 11 additions & 5 deletions azurerm/resource_arm_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -850,12 +850,16 @@ func resourceArmVirtualMachineDelete(d *schema.ResourceData, meta interface{}) e
}

if osDisk.Vhd != nil {
if err = resourceArmVirtualMachineDeleteVhd(*osDisk.Vhd.URI, meta); err != nil {
return fmt.Errorf("Error deleting OS Disk VHD: %+v", err)
if osDisk.Vhd.URI != nil {
if err = resourceArmVirtualMachineDeleteVhd(*osDisk.Vhd.URI, meta); err != nil {
return fmt.Errorf("Error deleting OS Disk VHD: %+v", err)
}
}
} else if osDisk.ManagedDisk != nil {
if err = resourceArmVirtualMachineDeleteManagedDisk(*osDisk.ManagedDisk.ID, meta); err != nil {
return fmt.Errorf("Error deleting OS Managed Disk: %+v", err)
if osDisk.ManagedDisk.ID != nil {
if err = resourceArmVirtualMachineDeleteManagedDisk(*osDisk.ManagedDisk.ID, meta); err != nil {
return fmt.Errorf("Error deleting OS Managed Disk: %+v", err)
}
}
} else {
return fmt.Errorf("Unable to locate OS managed disk properties from %s", name)
Expand Down Expand Up @@ -1078,7 +1082,9 @@ func flattenAzureRmVirtualMachineDataDisk(disks *[]compute.DataDisk, disksInfo [
}
if disk.ManagedDisk != nil {
l["managed_disk_type"] = string(disk.ManagedDisk.StorageAccountType)
l["managed_disk_id"] = *disk.ManagedDisk.ID
if disk.ManagedDisk.ID != nil {
l["managed_disk_id"] = *disk.ManagedDisk.ID
}
}
l["create_option"] = disk.CreateOption
l["caching"] = string(disk.Caching)
Expand Down

0 comments on commit 3bfc46e

Please sign in to comment.