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 Azure Resource Manager (ARM) virtual machine (VM) templates, connect template repositories to labs, and use templates to create VMs.
2
+
title: Create and use ARM templates for VMs
3
+
description: Learn how to view, edit, and store Azure Resource Manager (ARM) virtual machine (VM) templates, connect your template repositories to your labs, and access templates to use for creating VMs.
4
4
ms.topic: how-to
5
5
ms.author: rosemalcolm
6
6
author: RoseHJM
7
7
ms.date: 03/07/2025
8
8
ms.custom: UpdateFrequency2
9
+
10
+
#customer intent: As a lab user, I want to know how to create, manage, and access ARM templates, so I can use the templates to create VMs and let other lab users access my templates.
9
11
---
10
12
11
-
# Create and use ARM templates in DevTest Labs
13
+
# Create and use ARM templates for VMs in DevTest Labs
12
14
13
15
This article describes how DevTest Labs users can:
14
16
15
17
- 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.
18
+
- Store the ARM templates in source control repositories.
19
+
- Connect the ARM template repositories to Azure DevTest Labs so other lab users can access the templates.
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.
22
24
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).
25
+
Lab users can create their own ARM templates, modify existing ARM templates to meet their needs, or access preconfigured templates from their own or others' private repositories or the public [DevTest Labs GitHub repository](https://github.com/Azure/azure-devtestlab).
26
+
27
+
To create and deploy Azure VMs by using an ARM template, you can use any of the following options:
For more information about deployment, see [Template deployment process](/azure/azure-resource-manager/templates/overview#template-deployment-process).
24
38
25
39
## Prerequisites
26
40
27
-
- At least **DevTest Lab User** role in a lab.
41
+
- To view or save ARM templates while creating VMs, at least **DevTest Lab User** role in a DevTest Labs lab.
42
+
- To enable public repositories or add template repositories to labs, at least **Contributor** role in the lab.
You can customize and use an ARM template from any available Azure VM base to use for deploying more VMs of the same type.
32
48
33
49
1. On your lab's **Overview** page, select **Add** on the top toolbar.
34
50
1. On the **Choose a base** page, select the VM base you want.
35
-
1. On the **Create lab resource** page, configure settings and add desired artifacts to your template VM.
36
-
1. On the **Advanced Settings** tab, select **View ARM template**.
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.
40
-
51
+
1. On the **Create lab resource** tabs, configure settings and add desired artifacts to your template VM.
52
+
1. On the **Advanced Settings** tab, select **View ARM template** under **Automation** at the bottom of the form.
53
+
1. Copy and save the contents of the **View Azure Resource Manager template** page as a file named *azuredeploy.json*, and then close the page.
41
54
:::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.":::
55
+
1. If you want to create the VM or VMs immediately, select **Create** at the bottom of the **Create lab resource** page.
42
56
43
57
## Edit ARM templates for VMs
44
58
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.":::
59
+
When you reuse the ARM template to create more VMs, you can edit the values in your template file. To update only the `parameters` section of your template without having to edit the main template file, you can create and edit a separate file called *azuredeploy.parameters.json*.
60
+
61
+
For example, in training, demo, and trial scenarios, 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 the **Expiration date** on the **Advanced settings** tab. 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).
62
+
63
+
The following example ARM template `parameters` section includes an `expirationDate` parameter.
64
+
65
+
```json
66
+
"parameters": {
67
+
"newVMName": {
68
+
"type": "string",
69
+
"defaultValue": "vm01"
70
+
},
71
+
"labName": {
72
+
"type": "string",
73
+
"defaultValue": "Contoso1"
74
+
},
75
+
"size": {
76
+
"type": "string",
77
+
"defaultValue": "Standard_D2s_v3"
78
+
},
79
+
"userName": {
80
+
"type": "string",
81
+
"defaultValue": "labuser"
82
+
},
83
+
"hibernationEnabled": {
84
+
"type": "bool"
85
+
},
86
+
"expirationDate": {
87
+
"type": "string",
88
+
"defaultValue": "2025-03-15T07:00:00.000Z"
89
+
},
90
+
"password": {
91
+
"type": "securestring",
92
+
"defaultValue": "[[[user/VmPassword]]"
93
+
}
94
+
}
95
+
```
48
96
49
97
>[!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).
51
-
52
-
### Set VM expiration date
53
-
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).
98
+
>To create a URI value for automatically managing *nested templates*, you can add the `_artifactsLocation` and `_artifactsLocationSasToken` parameters to your `parameters` section or file. For more information about nested templates, see [Deploy nested Azure Resource Manager templates for testing environments](deploy-nested-template-environments.md).
57
99
58
100
### Create multiple VMs at once from the same template
59
101
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.
102
+
You can specify more than one instance of a template VM to be created at one time. When you create a lab VM in the Azure portal, you can specify **Number of instances** on the **Advanced Settings** tab. To add or change the number of instances in a reusable ARM template, you can edit or add the `copy: count` value in the `resources` section of the template.
61
103
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.
104
+
The following example ARM template`resources` section specifies creating two VMs.
63
105
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)
@@ -91,39 +142,38 @@ The following screenshot shows a typical ARM template folder structure in a repo
91
142
92
143
## Add template repositories to labs
93
144
94
-
To add your private ARM template repository to the lab so all lab users can access your templates:
145
+
To see and access the template repositories available to your lab:
95
146
96
147
1. On the lab's **Overview** page, select **Configuration and policies** from the left navigation.
97
148
1. On the **Configuration and policies** page, select **Repositories** under **External resources** in the left navigation.
98
-
1. Select **Add** in the top menu bar.
99
149
100
-
:::image type="content" source="media/devtest-lab-create-environment-from-arm/public-repo.png" alt-text="Screenshot that shows the Repositories configuration screen.":::
150
+
The **Public Artifact Repo** and **Public Environment Repo** at the [DevTest Labs public GitHub repository](https://github.com/Azure/azure-devtestlab) are available for all labs. 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).
151
+
152
+
If you're a lab owner or contributor, you can add your private ARM template repository to the lab so all lab users can access your templates.
153
+
154
+
1. On the **Repositories** page, select **Add** in the top menu bar.
155
+
156
+
:::image type="content" source="media/devtest-lab-use-arm-template/public-repo.png" alt-text="Screenshot that shows the Repositories configuration screen.":::
101
157
102
158
1. In the **Repositories** pane, enter the following information:
103
159
104
160
- **Name**: Enter the repository name to use in the lab.
105
161
- **Git clone URL**: Enter the Git HTTPS clone URL from GitHub or Azure Repos.
106
162
- **Branch** (optional): Enter the branch that has your ARM template definitions.
107
163
- **Personal access token**: Enter the personal access token to securely access your repository.
108
-
- To get a token from Azure Repos, select **User settings** > **Personal access tokens**.
164
+
- To get a token from Azure Repos, at upper right select **User settings** > **Personal access tokens**.
109
165
- To get a token from GitHub, under your profile, select **Settings** > **Developer settings** > **Personal access tokens**.
110
166
- **Folder paths**: Enter the folder for your ARM template definitions, relative to the Git clone URI.
111
167
112
168
1. Select **Save**.
113
169
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.":::
170
+
:::image type="content" source="media/devtest-lab-use-arm-template/repo-values.png" alt-text="Screenshot that shows settings for adding a new template repository to a lab.":::
115
171
116
172
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
173
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
-
123
-
124
-
### Related content
174
+
## Related content
125
175
126
-
-[Best practices for creating Azure Resource Manager templates](/azure/azure-resource-manager/templates/best-practices)
127
-
-[Add a Git repository to store custom artifacts and Resource Manager templates](devtest-lab-add-artifact-repo.md)
176
+
- [Best practices for creating ARM templates](/azure/azure-resource-manager/templates/best-practices)
177
+
- [Add a Git repository to store custom artifacts and ARM templates](devtest-lab-add-artifact-repo.md)
128
178
- [Use ARM templates to create DevTest Labs environments](devtest-lab-create-environment-from-arm.md)
129
179
- [ARM quickstart templates for DevTest Labs automation](https://github.com/Azure/azure-quickstart-templates)
0 commit comments