Creating an Azure Virtual Machine With ARM Template

In this blog post, we will show you how to create an Azure Virtual Machine with an ARM template. We will use the Microsoft Azure portal and Powershell to do so. First, let’s go over what an ARM template is and why you might want one for your virtual machine. After that, we’ll walk through deploying a VM from an ARM template of our own making!

About Azure ARM Templates

Azure ARM templates are a great option for deploying virtual machines to Azure. They are quick to deploy and easy to customize, which is handy when you’re setting up new environments. You can create your own ARM templates in Azure with templates that are available for download.

An Azure ARM template is an XML-based file that includes the parameters necessary for provisioning a virtual machine image in the Azure Resource Manager (ARM) deployment model, such as VM image name, VM configuration, number of instances, data disk size, data disk type, data disk name, operating system type and version.

How To Generate Azure ARM Template

First, create a new Resource Group from the button on the left of the portal. Name it whatever you’d like and choose a location that you’re interested in deploying your VM into. You can then click Create.

My preferred method to generate an ARM template is to go through the process of creating a virtual machine in the portal and before creating the template selecting the option to download it.

This method allows me to customise the VM and validate the settings before deploying it.

The downloaded file will have two files after unzipping it. The parameters.json file has the values I entered when creating the VM. This file allows me to make changes to the temple (like VM name, etc).

The template.json file has the actual configuration and values from the first files are using to run the template.

Deploying An ARM Template

To deploy my VM using a downloaded template, I am using the Az PowerShell module (make sure you are running the latest version)

For the VM to work, I will need to pass the Administrator username via PowerShell.

Open PowerShell and open the folder you save the templates to run the cmdlet below to see the password for the VM administrator.

$SecurePwd = ConvertTo-SecureString "PASSWORDHERE" -AsPlainText -Force

Next, I will connect to Azure and set the subscription.

Set-AzContext -Subscription pay-as-you-go

Finally, I will deploy the template.

New-AzResourceGroupDeployment -ResourceGroupName avd -TemplateFile .\template.json -TemplateParameterFile .\parameters.json -adminPassword  $SecurePwd

At this stage, the VM will deploy and be ready in 5 minutes.