You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: Learn how to view, edit, save, and store ARM virtual machine (VM) templates, and connect template repositories to Azure DevTest Labs.
2
+
title: Create and use ARM templates
3
+
description: Learn how to view, edit, save, and store Azure Resource Manager (ARM) virtual machine (VM) templates, connect template repositories to labs, and use templates to create VMs.
4
4
ms.topic: how-to
5
5
ms.author: rosemalcolm
6
6
author: RoseHJM
7
-
ms.date: 09/30/2023
7
+
ms.date: 03/07/2025
8
8
ms.custom: UpdateFrequency2
9
9
---
10
10
11
-
# Use ARM templates to create DevTest Labs virtual machines
11
+
# Create and use ARM templates in DevTest Labs
12
12
13
-
You can use Azure Resource Manager (ARM) templates to create preconfigured Azure virtual machines (VMs) in Azure DevTest Labs.
13
+
This article describes how DevTest Labs users can:
14
+
15
+
- View, edit, and save Azure Resource Manager (ARM) templates for creating Azure VMs.
16
+
- Store ARM templates in source control repositories.
17
+
- Connect ARM template repositories to Azure DevTest Labs so other lab users can access the templates.
Single-VM ARM templates use the [Microsoft.DevTestLab/labs/virtualmachines](/azure/templates/microsoft.devtestlab/2018-09-15/labs/virtualmachines) resource type. Each VM created with this resource type appears as a separate item in the lab's **My virtual machines** list.
21
+
ARM templates for VM creation use the [Microsoft.DevTestLab/labs/virtualmachines](/azure/templates/microsoft.devtestlab/2018-09-15/labs/virtualmachines?pivots=deployment-language-arm-template) resource type. Each lab VM created with this resource type appears as a separate item in the lab's **My virtual machines** list.
18
22
19
-
You can create your own single-VM ARM templates, access the public [DevTest Labs GitHub repository](https://github.com/Azure/azure-devtestlab) for preconfigured templates, or modify existing ARM templates to meet your needs. Lab users can use your ARM templates to create and deploy Azure VMs.
23
+
Lab users can use ARM templates to create and deploy Azure VMs. Users can create their own ARM templates, modify existing ARM templates to meet their needs, or access preconfigured templates from the public [DevTest Labs GitHub repository](https://github.com/Azure/azure-devtestlab).
20
24
21
-
This article describes how to:
25
+
## Prerequisites
22
26
23
-
- View, edit, and save ARM templates for Azure VMs.
24
-
- Store ARM templates in source control repositories.
25
-
- Connect ARM template repositories to Azure DevTest Labs so lab users can access the templates.
27
+
- At least **DevTest Lab User** role in a lab.
26
28
27
-
## View, edit, and save ARM templates for VMs
29
+
## View and save ARM templates for VMs
28
30
29
-
You can customize and use an ARM template from any Azure VM base to deploy more of the same VM type in DevTest Labs.
31
+
You can customize and use an ARM template from any available Azure VM base to use for deploying more VMs of the same type.
30
32
31
33
1. On your lab's **Overview** page, select **Add** on the top toolbar.
32
-
1. On the **Choose a base** page, select the type of VM you want.
34
+
1. On the **Choose a base** page, select the VM base you want.
33
35
1. On the **Create lab resource** page, configure settings and add desired artifacts to your template VM.
34
36
1. On the **Advanced Settings** tab, select **View ARM template**.
35
-
1. Copy and [save the ARM template](#store-arm-templates-in-git-repositories) to use for creating more VMs.
37
+
1. Copy and save the ARM template to use for creating VMs.
38
+
1. Close the ARM template page.
39
+
1. If you want to create an instance of the VM immediately, select **Create** at the bottom of the form.
36
40
37
41
:::image type="content" source="media/devtest-lab-use-arm-template/devtestlab-lab-copy-rm-template.png" alt-text="Screenshot that shows an ARM template to save for later use.":::
38
42
39
-
1. If you want to create an instance of the VM now, on the **Basic Settings** tab, select **Create**.
43
+
## Edit ARM templates for VMs
44
+
45
+
To reuse the ARM template to create more VMs, you can update the `parameters` section of your template file. You can also create a *parameters* JSON file that customizes just the parameters, without having to edit the main template file.
46
+
47
+
:::image type="content" source="media/devtest-lab-use-arm-template/devtestlab-lab-custom-params.png" alt-text="Customize parameters using a JSON file.":::
48
+
49
+
>[!TIP]
50
+
>You can add the `_artifactsLocation` and `_artifactsLocationSasToken` parameters to your parameters section or file to create a URI value for automatically managing nested templates. For more information about nested templates, see [Deploy nested Azure Resource Manager templates for testing environments](deploy-nested-template-environments.md).
40
51
41
52
### Set VM expiration date
42
53
43
-
For scenarios such as training, demos, and trials, you might want to delete VMs automatically after a certain date so they don't keep incurring costs. When you create a lab VM from the Azure portal, you can set an expiration date by specifying the **Expiration date** property on the **Advanced settings** tab. For an ARM template that defines the `expirationDate` property, see [Creates a new virtual machine in a Lab with a specified expiration date](https://github.com/Azure/azure-devtestlab/tree/master/samples/DevTestLabs/QuickStartTemplates/101-dtl-create-vm-username-pwd-customimage-with-expiration).
54
+
For scenarios such as training, demos, and trials, you can automatically delete VMs after a certain date so they don't keep incurring costs. When you create a lab VM in the Azure portal, you can specify an **Expiration date** on the **Advanced settings** tab.
55
+
56
+
You can also add an `expirationDate` property to the `parameters` section of your template file. For an example, see [Create a new VM in a lab with a specified expiration date](https://github.com/Azure/azure-devtestlab/tree/master/samples/DevTestLabs/QuickStartTemplates/101-dtl-create-vm-username-pwd-customimage-with-expiration).
57
+
58
+
### Create multiple VMs at once from the same template
59
+
60
+
You can specify more than one instance of a template VM to be created at a time. When you create a lab VM in the Azure portal, you can specify **Number of instances** on the **Advanced Settings** tab.
61
+
62
+
To add or change the number of instances in a reusable JSON template, you can edit or add the `copy/count` value to the `resources` section of the template.
63
+
64
+
There are two other options for simultaneously creating multiple VMs from the same template:
65
+
66
+
- Use the [Azure DevOps Tasks extension](https://marketplace.visualstudio.com/items?itemName=ms-azuredevtestlabs.tasks)
67
+
-[Use Windows PowerShell to deploy the generated ARM template](/azure/azure-resource-manager/templates/deploy-powershell)
As a best practice for infrastructure as code and configuration as code, store your ARM templates in source control. DevTest Labs can load your ARM templates directly from your GitHub or Azure Repos source control repository. You can then use the templates throughout your release cycle, from development through test to production environments.
73
+
As a best practice for infrastructure as code and configuration as code, store your ARM templates in source control. DevTest Labs can load ARM templates directly from GitHub or Azure Repos source control repositories. You can then use the templates throughout your release cycle, from development through test to production environments.
50
74
51
75
Use the following file structure to store an ARM template in a source control repository:
52
76
53
77
- Name the main template file *azuredeploy.json*.
54
-
55
-
- To reuse the ARM template, you need to update the `parameters` section of *azuredeploy.json*. You can create a *parameter.json* file that customizes just the parameters, without having to edit the main template file. Name this parameter file *azuredeploy.parameters.json*.
56
-
57
-
:::image type="content" source="media/devtest-lab-use-arm-template/devtestlab-lab-custom-params.png" alt-text="Customize parameters using a JSON file.":::
58
-
59
-
In the parameters file, you can use the parameters `_artifactsLocation` and `_artifactsLocationSasToken` to construct a `parametersLink` URI value for automatically managing nested templates. For more information about nested templates, see [Deploy nested Azure Resource Manager templates for testing environments](deploy-nested-template-environments.md).
60
-
61
-
- You can define metadata that specifies the template display name and description in a file named *metadata.json*.
78
+
- Name any standalone parameter customization file *azuredeploy.parameters.json*.
79
+
- Optionally, define metadata that specifies the template display name and description in a file named *metadata.json*.
62
80
63
81
```json
64
82
{
@@ -69,48 +87,43 @@ Use the following file structure to store an ARM template in a source control re
69
87
70
88
The following screenshot shows a typical ARM template folder structure in a repository.
71
89
72
-
:::image type="content" source="media/devtest-lab-create-environment-from-arm/main-template.png" alt-text="Screenshot that shows key ARM template files in a repository.":::
90
+
:::image type="content" source="media/devtest-lab-use-arm-template/repo-structure.png" alt-text="Screenshot that shows key ARM template files in a repository.":::
73
91
74
92
## Add template repositories to labs
75
93
76
-
Add your template repositories to your lab so all lab users can access the templates.
94
+
To add your private ARM template repository to the lab so all lab users can access your templates:
77
95
78
96
1. On the lab's **Overview** page, select **Configuration and policies** from the left navigation.
79
-
80
97
1. On the **Configuration and policies** page, select **Repositories** under **External resources** in the left navigation.
81
-
82
-
On the **Repositories** screen, the **Public Artifact Repo** and **Public Environment Repo** are automatically present for all labs, and connect to the [DevTest Labs public GitHub repository](https://github.com/Azure/azure-devtestlab). If these repos aren't enabled for your lab, you can enable them by selecting the checkboxes next to **Public Artifact Repo** and **Public Environment Repo**, and then selecting **Enable** on the top menu bar. For more information, see [Enable and configure public environments](devtest-lab-create-environment-from-arm.md#configure-public-environment-settings).
83
-
84
-
1. To add your private ARM template repository to the lab, select **Add** in the top menu bar.
98
+
1. Select **Add** in the top menu bar.
85
99
86
100
:::image type="content" source="media/devtest-lab-create-environment-from-arm/public-repo.png" alt-text="Screenshot that shows the Repositories configuration screen.":::
87
101
88
102
1. In the **Repositories** pane, enter the following information:
89
103
90
-
-**Name**: Enter a repository name to use in the lab.
104
+
-**Name**: Enter the repository name to use in the lab.
91
105
-**Git clone URL**: Enter the Git HTTPS clone URL from GitHub or Azure Repos.
92
106
-**Branch** (optional): Enter the branch that has your ARM template definitions.
93
107
-**Personal access token**: Enter the personal access token to securely access your repository.
94
108
- To get a token from Azure Repos, select **User settings** > **Personal access tokens**.
95
-
- To get your token from GitHub, under your profile, select **Settings** > **Developer settings** > **Personal access tokens**.
109
+
- To get a token from GitHub, under your profile, select **Settings** > **Developer settings** > **Personal access tokens**.
96
110
-**Folder paths**: Enter the folder for your ARM template definitions, relative to the Git clone URI.
97
111
98
112
1. Select **Save**.
99
113
100
114
:::image type="content" source="media/devtest-lab-create-environment-from-arm/repo-values.png" alt-text="Screenshot that shows adding a new template repository to a lab.":::
101
115
102
-
The repository now appears in the **Repositories** list for the lab. Users can now use the repository templates to [create multi-VM DevTest Labs environments](devtest-lab-create-environment-from-arm.md). Lab administrators can use the templates to [automate lab deployment and management tasks](devtest-lab-use-arm-and-powershell-for-lab-resources.md#arm-template-automation).
116
+
The repository now appears in the **Repositories** list for the lab. Lab users can use the repository templates to [create multi-VM DevTest Labs environments](devtest-lab-create-environment-from-arm.md). Lab administrators can use the templates to [automate lab deployment and management tasks](devtest-lab-use-arm-and-powershell-for-lab-resources.md#arm-template-automation).
117
+
118
+
>[!NOTE]
119
+
>On the **Repositories** page, the **Public Artifact Repo** and **Public Environment Repo** are available for all labs. These links connect to the [DevTest Labs public GitHub repository](https://github.com/Azure/azure-devtestlab).
120
+
>
121
+
>If these repos aren't enabled for your lab, a lab owner or contributor can enable them by selecting the checkboxes next to **Public Artifact Repo** and **Public Environment Repo**, and then selecting **Enable** on the top menu bar. For more information, see [Enable and configure public environments](devtest-lab-create-environment-from-arm.md#configure-public-environment-settings).
122
+
103
123
104
-
### How do I create multiple VMs from the same template at once?
105
-
You have two options for simultaneously creating multiple VMs from the same template:
106
-
107
-
- You can use the [Azure DevOps Tasks extension](https://marketplace.visualstudio.com/items?itemName=ms-azuredevtestlabs.tasks).
108
-
- You can [generate a Resource Manager template](devtest-lab-add-vm.md#create-and-add-virtual-machines) while you're creating a VM, and [deploy the Resource Manager template from Windows PowerShell](../azure-resource-manager/templates/deploy-powershell.md).
109
-
- You can also specify more than one instance of a machine to be created during virtual machine creation. To learn more about creating multiple instances of virtual machines, see the doc on [creating a lab virtual machine](devtest-lab-add-vm.md).
110
-
111
-
### Next steps
124
+
### Related content
112
125
113
-
-[Best practices for creating Azure Resource Manager templates](../azure-resource-manager/templates/best-practices.md)
126
+
-[Best practices for creating Azure Resource Manager templates](/azure/azure-resource-manager/templates/best-practices)
114
127
-[Add a Git repository to store custom artifacts and Resource Manager templates](devtest-lab-add-artifact-repo.md)
115
128
-[Use ARM templates to create DevTest Labs environments](devtest-lab-create-environment-from-arm.md)
116
129
-[ARM quickstart templates for DevTest Labs automation](https://github.com/Azure/azure-quickstart-templates)
0 commit comments