Description
When trying to create an Azure VM from existing vhds, I create a config and use Add-AzureVMDataDisk
to add in the disk configuration.
$vm = New-AzureVMConfig -VMName "demo" -VMSize $size
$vm = Set-AzureVMOSDisk -VM $vm -Name "os-disk.vhd" -VhdUri $osDiskUri -CreateOption attach -Windows -Caching ReadWrite
However, when I try to attach the existing data disk, I have to specify DiskSizeInGB
(the parameter is mandatory):
$vm = Add-AzureVMDataDisk -VM $vm -VhdUri $dataDiskUri -Name "data-disk.vhd" -CreateOption attach -Caching ReadOnly -DiskSizeInGB 200
The command succeeds, but when passing this configuration to New-AzureVM
, the operation fails stating that the disk Uri exists and that a non-existing uri should be supplied when creating an empty disk. Similarly, if I supply the data disk uri as sourceImageUri
and provide a new uri (so that New-AzureVM
copies the disk) I get an error stating that "you cannot specify size and sourceImageUri".
I found that if I set the size of the data disk to null in the config, then the New-AzureVM
operation succeeds (for both createOption = attach
and createOption = fromImage
):
$vm.StorageProfile.DataDisks[0].DiskSizeGB = $null
There are 2 solutions:
- The
New-AzureVM
cmdlet should ignore the size forCreateOption
fromImage
orattach
- The
Add-AzureDataDisk
cmdlet should not requireDiskSizeInGB
parameter, setting the value to null if it is not supplied