Create virtual machines using an Azure Resource Manager template

When you are creating a virtual machine (VM) in DevTest Labs through the Azure portal, you can view the Azure Resource Manager template before you save the VM. The template can then be used as a basis to create more lab VMs with the same settings.

This article describes Multi-VM vs. single-VM Resource Manager templates and shows you how to view and save a template when creating a VM.


This article has been updated to use the Azure Az PowerShell module. The Az PowerShell module is the recommended PowerShell module for interacting with Azure. To get started with the Az PowerShell module, see Install Azure PowerShell. To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.

Multi-VM vs. single-VM Resource Manager templates

There are two ways to create VMs in DevTest Labs using a Resource Manager template: provision the Microsoft.DevTestLab/labs/virtualmachines resource or provision the Microsoft.Compute/virtualmachines resource. Each is used in different scenarios and requires different permissions.

  • Resource Manager templates that use a Microsoft.DevTestLab/labs/virtualmachines resource type (as declared in the “resource” property in the template) can provision individual lab VMs. Each VM then shows up as a single item in the DevTest Labs virtual machines list:

    Screenshot that shows the list of virtual machines as single items in the DevTest Labs virtual machines list.

    This type of Resource Manager template can be provisioned through the Azure PowerShell command New-AzResourceGroupDeployment or through the Azure CLI command az deployment group create. It requires administrator permissions, so users who are assigned with a DevTest Labs user role can’t perform the deployment.

  • Resource Manager templates that use a Microsoft.Compute/virtualmachines resource type can provision multiple VMs as a single environment in the DevTest Labs virtual machines list:

    List of VMs as single items in the DevTest Labs virtual machines list

    VMs in the same environment can be managed together and share the same lifecycle. Users who are assigned with a DevTest Labs user role can create environments using those templates as long as the administrator has configured the lab that way.

The remainder of this article discusses Resource Manager templates that use Microsoft.DevTestLab/labs/virtualmachines. These are used by lab admins to automate lab VM creation (for example, claimable VMs) or golden image generation (for example, image factory).

Best practices for creating Azure Resource Manager templates offers many guidelines and suggestions to help you create Azure Resource Manager templates that are reliable and easy to use.

View and save a virtual machine's Resource Manager template

  1. Follow the steps at Create your first VM in a lab to begin creating a virtual machine.

  2. Enter the required information for your virtual machine and add any artifacts you want for this VM.

  3. Switch to the Advanced Settings tab.

  4. At the bottom of the Configure settings window, choose View ARM template.

  5. Copy and save the Resource Manager template to use later to create another virtual machine.

    Resource Manager template to save for later use

After you have saved the Resource Manager template, you must update the parameters section of the template before you can use it. You can create a parameter.json that customizes just the parameters, outside of the actual Resource Manager template.

Customize parameters using a JSON file

The Resource Manager template is now ready to use to create a VM.

Set expiration date

In scenarios such as training, demos and trials, you may want to create virtual machines and delete them automatically after a fixed duration so that you don’t incur unnecessary costs. You can create a lab VM with an expiration date by specifying the expirationDate property for the VM. Check out the same Resource Manager template in our GitHub repository.

Next steps