Another day, one of my costumer wants to rebuild a virtual machine from the existing VHD and place on the new Resource Group and on a different VLAN, but without transferring VHD. The idea was to park the VHD on a storage account to avoid transferring this huge VHD.
First, I want to clarify if you delete the VM, you are not deleting the all the resources, that means that the vhd(s), network adapter9s) or the network IPs will remain intact. You are only deleting the compute section of the VM. That means you can redeploy using the same configuration, or change the network, for example.
To achieve that though, you need to do it through PowerShell and/or using JSON files.
So, if you change the original JSON file just replacing the VHD you will probably get an error message saying, “Cannot attach an existing OS disk if the VM is created from a platform or user image.”
To avoid that you have to change the JSON file to reflect createOption to use the attach method instead.
Here is what you need to change:
Original JSON:
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "[parameters('windowsOSVersion')]",
"version": "latest"
},
"osDisk": { "createOption": "FromImage"
},
}
Replace with:
"storageProfile": {
"osDisk": { "createOption": "attach",
"managedDisk": {
"id": [Managed_Disk_ID]
},
}
}
Cheers,
Marcos Nogueira
Azure MVP
azurecentric.com
Twitter: @mdnoga
Comments