I have an image stored in Azure that I want to spin up multiple VMs from. I've created a template that will create the necessary resources for me and all of them succeed except the VM creation.
Using CreateOption.FromImage runs the deployment for around 40 minutes until I get the error:
'OS Provisioning for VM 'vmName' did not finish in the allotted time. However, the VM guest agent was detected running. This suggests the guest OS has not been properly prepared to be used as a VM image (with CreateOption=FromImage). To resolve this issue, either use the VHD as is with CreateOption=Attach or prepare it properly for use as an image
Changing CreateOption.FromImage
to CreateOption.Attach
gives me the following error immediately:
Cannot attach an existing OS disk if the VM is created from a platform or user image.
What I'm trying to achieve through the template:
- Point to master image
- Supply desired destination for a copy of the master
- Copy the master image to the destination
- Create the VM
- Attach the copy to the VM
Below is the VM portion of the template I'm using to deploy:
{
"apiVersion": "2015-06-15",
"type": "Microsoft.Compute/virtualMachines",
"name": "[parameters('vmName')]",
"location": "[resourceGroup().location]",
"tags": {
"displayName": "VirtualMachine"
},
"dependsOn": [
"[concat('Microsoft.Network/networkInterfaces/', parameters('nicName'))]"
],
"properties": {
"osProfile": {
"computerName": "[parameters('vmName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
},
"hardwareProfile": {
"vmSize": "[variables('vmSize')]"
},
"storageProfile": {
"osDisk": {
"name": "[parameters('OSDiskName')]",
"osType": "windows",
"caching": "ReadWrite",
"createOption": "FromImage",
"image": {
"uri": "[concat('https://', parameters('storageAccountName'), '.blob.core.windows.net/', parameters('sourceStorageContainerName'), '/', parameters('sourceVHDName'), '.vhd')]"
},
"vhd": {
"uri": "[concat('https://', parameters('storageAccountName'), '.blob.core.windows.net/', parameters('vhdStorageContainerName'), '/', parameters('OSDiskName'), '.vhd')]"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('nicName'))]"
}
]
}
}
}
If you are using the image that is not sysprepped to create VM, it could cause the error, so please make sure your image is sysprepped.
When you specify CreateOption to Attach ( it will create a virtual machine from a specialized disk), do not specify the SourceImageUri parameter. For more information, please check “-CreateOption” from this documentation.