This blog post walks you through the manual process of adding an Azure virtual machine that uses managed disk to an availability set using a manual process purely inside the Azure portal (https://portal.azure.com). Note that if you have virtual machines using unmanaged disks that needs to be included in an availability set, you can use a PowerShell module posted at the TechNet Gallery using this link.
This blog assumes you have a great understanding of what is an availability set, if you don’t know what this is, please refer to Azure availability sets guidelines for Windows VMs and Manage the availability of Windows virtual machines in Azure. It also assume that you have the concepts of managed disks in Azure, if not, please refer to Azure Managed Disks Overview.
Finally we need the following items already deployed in Azure:
- Availability set aligned to be used with managed disks
- The virtual machine using managed disks that is not yet associated with an availability set
This example also assumes that you don’t have any data disk attached to your virtual machine, if that’s the case you need to change the dataDisks in a similar way I do with the osDisk property.
- Sign in at https://portal.azure.com
- Export the current template definition of you live resource (virtual machine in this case)
- At the top navigation bar of Azure Portal, click in the search field and type “resource explorer”
- Click on “resource explorer”
- Easiest way to navigate over your resources is expanding Subscriptions->Subscription Name->Providers->Microsoft.Compute->virtualMachines->VM Name
- On the details pane, where the template shows up, copy all its template contents and save it locally with notepad or any tool you may find appropriate.
- Close “Resource Explorer”
- Delete your virtual machine (yes, as of the day this article was written you can delete the virtual machine in Azure and the disks gets preserved)
- Create a new deployment
- Click on “+ New”, at the search field, type “template deployment” and press enter
- Select “Template Deployment” from the “Everything” blade and click “Create”
- At the “Custom deployment” blade, click “Edit template”. This will bring a bring a blank template structure.
- At line 5, between the square brackets “”, paste the template you saved in the file.
Template after content was pasted
- Delete the line that contains “vmId” property, in this guide this is line 7
- Replace the contents of imageReference:
- Replace the contents of osDisk:
Where <Resource ID of your OS Disk> needs to point to the resource ID of the currently existing OS Disk, which can be obtained by searching for the disk in the search field of the top navigation pane and copying the Resource ID property (note that you need to open a new tab on your internet browser)
- Replace the content of “osProfile”
- Insert the new element for the Availability Set. For that, go to the line where it starts with “provisioningState”, Insert a line before “provisioningState” and paste the following element (including the extra comma)
To obtain the resource Id:
- At the top navigation pane, click the search icon
- Type the availability set name at the search field
- Select the availability set
- Click “Properties”
- Copy the Resource Id by clicking at the copy icon ()
- Notice that if your VM have any installed extension, you need to remove them from this template otherwise the deployment may fail, you can always add the extensions back later, dealing with extensions is out of scope of this blog post.
- Just after the very last property of your template, in my case “name”, which is the virtual machine name, add a comma at the end of the “name” line and add the following line (you must have a comma before this new “apiVersion”, otherwise validation will fail.
- Your template code should be similar to this
- Click “Save”
- Select the same exact resource group where your virtual machine existed at the “Resource group” field and same location if available to choose, then click “I agree to the terms and conditions stated above” and click “Purchase”
If any errors come up, you can always click in the notification icon at the top navigation pane and select the failed deployment:
This will bring the failed deployment blade
Again, if you have virtual machines using unmanaged disks that needs to be included in an availability set, you can use a PowerShell module that I developed and poste at the TechNet Gallery using this link.
That’s it for this blog and I hope this helps.