Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Virtual Machine: Handling disk.ManagedDisk.ID being nil #1947

Merged
merged 1 commit into from
Sep 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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