Skip to content

Commit 9373ac9

Browse files
authored
Merge pull request #297531 from v-thepet/dtl9
Freshness Edit: Azure DevTest Labs Set #5
2 parents 815e5da + 0e7b52e commit 9373ac9

12 files changed

+173
-156
lines changed

articles/devtest-labs/deploy-nested-template-environments.md

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,38 @@
11
---
2-
title: Deploy nested ARM template environments
3-
description: Learn how to nest Azure Resource Manager (ARM) templates to deploy Azure DevTest Labs environments.
2+
title: Nested ARM templates for lab environments
3+
description: Learn about using nested Azure Resource Manager (ARM) templates to deploy Azure DevTest Labs environments.
44
ms.topic: how-to
55
ms.custom: devx-track-arm-template, UpdateFrequency2
66
ms.author: rosemalcolm
77
author: RoseHJM
8-
ms.date: 09/30/2023
8+
ms.date: 04/02/2025
9+
10+
#customer intent: As a DevTest labs user, I want to learn about using nested templates to deploy environments so I can take advantage of their testing, reuse, and readability benefits.
911
---
1012

11-
# Deploy DevTest Labs environments by using nested templates
13+
# Nested templates in DevTest Labs environments
1214

13-
A nested deployment runs secondary Azure Resource Manager (ARM) templates from within a main template. This article shows an example of nesting templates to deploy an Azure DevTest Labs environment. DevTest Labs environments contain multiple infrastructure-as-a-service (IaaS) virtual machines (VMs) with platform-as-a-service (PaaS) resources installed. You can provision the PaaS resources and VMs by using ARM templates.
15+
An Azure DevTest Labs *environment* consists of multiple infrastructure-as-a-service (IaaS) virtual machines (VMs) with platform-as-a-service (PaaS) resources installed. You can provision and deploy DevTest Labs environments by using Azure Resource Manager (ARM) templates.
1416

15-
Decomposing a deployment into a set of targeted, purpose-specific templates provides testing, reuse, and readability benefits. For general information about nested templates, including code samples, see [Using linked and nested templates when deploying Azure resources](../azure-resource-manager/templates/linked-templates.md).
17+
To deploy complex solutions like environments, you can break a template into secondary templates, and deploy these templates through a main template. This article describes using *nested templates* to deploy a DevTest Labs environment. Using a set of targeted, purpose-specific templates to deploy an environment promotes testing, reuse, and readability.
1618

19+
For general information about nested templates, including code samples, see [Use linked and nested templates when deploying Azure resources](/azure/azure-resource-manager/templates/linked-templates).
1720

1821
[!INCLUDE [direct-azure-deployment-environments](includes/direct-azure-deployment-environments.md)]
1922

20-
## Deploy nested templates with Visual Studio
21-
22-
The Azure Resource Group project template in Visual Studio makes it easy to develop and debug ARM templates. When you add a nested template to the main *azuredeploy.json* template file, Visual Studio adds the following items to make the template more flexible:
23-
24-
- A subfolder with the secondary template and parameters files
25-
- Variable names in the main template file
26-
- Two key parameters, `_artifactsLocation` and `_artifactsLocationSasToken`
27-
28-
In DevTest Labs, you store ARM templates in a Git repository that you link to the lab. When you use one of the linked repository templates to create a new environment, the deployment copies the template files into an Azure Storage container in the lab. When you add a nested template resource to the repository and main template file, Visual Studio identifies the `_artifactsLocation` and `_artifactsLocationSasToken` values, copies the subfolders to the storage container, and inserts the location and Shared Access Signature (SaS) token into the parameters files.
23+
## Nested template deployment
2924

30-
## Nested template folder structure
25+
In DevTest Labs, you can store ARM templates in a Git repository linked to a lab. When you use repository templates to create an environment, DevTest Labs copies all template and artifact files, including nested template files, into the lab's Azure Storage container.
3126

32-
In the following template example, the Git repository folder has a subfolder, *nestedtemplates*, with the nested template files *NestOne.json* and *NestOne.parameters.json*. The *azuredeploy.json* main template file builds the URI for the secondary templates by using the artifacts location, nested template folder, and nested template filename. The URI for the parameters file is the artifacts location, nested template folder, and nested template parameters file. You can add more nested template subfolders to the primary folder, but at only one level of nesting.
27+
The main *azuredeploy.json* template file for a nested template deployment uses `Microsoft.Resources/deployments` objects to call linked secondary templates. You provide URI values for the linked templates, and generate a Shared Access Signature (SaS) token for the deployment.
3328

34-
The following screenshot shows the project structure in Visual Studio:
29+
The deployment uses Azure PowerShell `New-AzResourceGroupDeployment` or Azure CLI `az deployment group create`, specifying the main template URI and the SaS token. For more information, see [Tutorial: Deploy a linked template](/azure/azure-resource-manager/templates/deployment-tutorial-linked-template).
3530

36-
![Screenshot that shows the nested template project structure in Visual Studio.](./media/deploy-nested-template-environments/visual-studio-project-structure.png)
31+
## Nested template example
3732

38-
## Nested deployment example
33+
The following example *azuredeploy.json* main template file shows the code for a nested deployment. The main template file defines links to the nested template.
3934

40-
The following example shows the main *azuredeploy.json* ARM template file for the nested deployment:
35+
The link URI for the secondary template concatenates the artifacts location, nested template folder, nested template filename, and artifacts Shared Access Signature (SaS) token location. The URI for the secondary parameters file uses the artifacts location, nested template folder, nested parameter filename, and artifacts SaS token location.
4136

4237
```json
4338

@@ -75,7 +70,7 @@ The following example shows the main *azuredeploy.json* ARM template file for th
7570
"outputs": {}
7671
```
7772

78-
## Next steps
73+
## Related content
7974

8075
- For more information about DevTest Labs environments, see [Use ARM templates to create DevTest Labs environments](devtest-lab-create-environment-from-arm.md).
81-
- For more information about using the Visual Studio Azure Resource Group project template, including code samples, see [Creating and deploying Azure resource groups through Visual Studio](../azure-resource-manager/templates/create-visual-studio-deployment-project.md).
76+
- For more information about using the Visual Studio Azure Resource Group project template, including code samples, see [Create and deploy Azure resource groups through Visual Studio](/azure/azure-resource-manager/templates/create-visual-studio-deployment-project).

articles/devtest-labs/devtest-lab-create-custom-image-from-vhd-using-powershell.md

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,101 +4,104 @@ description: Automate creation of a custom image in Azure DevTest Labs from a VH
44
ms.topic: how-to
55
ms.author: rosemalcolm
66
author: RoseHJM
7-
ms.date: 09/30/2023
7+
ms.date: 04/02/2025
88
ms.custom: devx-track-azurepowershell, UpdateFrequency2
9+
10+
#customer intent: As a lab administrator, I want to create custom images from VHD files, so I can make the custom images available to lab users as bases for creating lab VMs.
911
---
1012

11-
# Create a custom image from a VHD file with PowerShell
13+
# Create a custom image from a VHD file by using Azure PowerShell
1214

1315
[!INCLUDE [devtest-lab-create-custom-image-from-vhd-selector](../../includes/devtest-lab-create-custom-image-from-vhd-selector.md)]
1416

17+
In this article, you learn how to create an Azure DevTest Labs virtual machine (VM) custom image from a virtual hard disk (VHD) file by using Azure PowerShell. You can also [use the Azure portal to create a custom image](devtest-lab-create-template.md).
18+
1519
[!INCLUDE [devtest-lab-custom-image-definition](../../includes/devtest-lab-custom-image-definition.md)]
1620

17-
[!INCLUDE [devtest-lab-upload-vhd-options](../../includes/devtest-lab-upload-vhd-options.md)]
21+
## Prerequisites
1822

19-
[!INCLUDE [updated-for-az](~/reusable-content/ce-skilling/azure/includes/updated-for-az.md)]
23+
- **Owner** or **Contributor** permissions in an existing lab.
24+
- Azure PowerShell installed. You can use [Azure Cloud Shell](/azure/cloud-shell/quickstart) or [install PowerShell locally](/powershell/azure/install-azure-powershell).
2025

21-
## PowerShell steps
26+
- In Cloud Shell, select the **PowerShell** environment.
27+
- For a local PowerShell installation, run `Update-Module -Name Az` to get the latest version of Azure PowerShell, and run [Connect-AzAccount](/powershell/module/az.accounts/connect-azaccount) to sign in to Azure.
2228

23-
The following steps walk you through creating a custom image from a VHD file by using Azure PowerShell:
29+
- A VHD file uploaded to the Azure Storage account for the lab. To upload a VHD file:
2430

25-
1. At a PowerShell command prompt, sign in to your Azure account with the **Connect-AzAccount** cmdlet:
31+
1. Go to your lab storage account in the Azure portal and select **Upload**.
32+
1. Browse to and select the VHD file, select the **uploads** container or create a new container named **uploads** for the file, and then select **Upload**.
2633

27-
```powershell
28-
Connect-AzAccount
29-
```
34+
You can also upload a VHD file by following the instructions in any of these articles:
35+
36+
- [Upload a VHD file by using the AzCopy command-line utility](devtest-lab-upload-vhd-using-azcopy.md)
37+
- [Upload a VHD file by using Microsoft Azure Storage Explorer](devtest-lab-upload-vhd-using-storage-explorer.md)
38+
- [Upload a VHD file by using PowerShell](devtest-lab-upload-vhd-using-powershell.md)
3039

31-
1. Select your Azure subscription with the **Select-AzSubscription** cmdlet. Replace \<subscription ID> with your subscription ID GUID.
40+
## Create a custom image
41+
42+
The following Azure PowerShell steps create a DevTest Labs custom image from an uploaded VHD file by using a deployment template from the public [DevTest Labs template repository](https://github.com/Azure/azure-devtestlab/tree/master/samples/DevTestLabs/QuickStartTemplates/201-dtl-create-customimage-from-vhd).
43+
44+
1. After you sign in to Azure, select the subscription you want to use by running `Select-AzSubscription`. Replace the `<subscription ID>` placeholder with your subscription ID.
3245

3346
```powershell
3447
$subscriptionId = '<subscription ID>'
3548
Select-AzSubscription -SubscriptionId $subscriptionId
3649
```
3750

38-
1. Get the lab object by calling the **Get-AzResource** cmdlet. Replace the \<lab resource group name> and \<lab name> placeholders with your own resource group and lab names.
51+
1. Use [Get-AzResource](/powershell/module/az.resources/get-azresource) to get the lab object. Replace the `<lab resource group name>` and `<lab name>` placeholders with your own resource group and lab names, which you can get from the Azure portal.
3952

4053
```powershell
4154
$labRg = '<lab resource group name>'
4255
$labName = '<lab name>'
4356
$lab = Get-AzResource -ResourceId ('/subscriptions/' + $subscriptionId + '/resourceGroups/' + $labRg + '/providers/Microsoft.DevTestLab/labs/' + $labName)
4457
```
4558

46-
1. Replace the placeholder for the **$vhdUri** variable with the URI of your uploaded VHD file. You can get the VHD file's URI from its blob page in the lab's storage account in the Azure portal. An example VHD URI is: `https://acontosolab1234.blob.core.windows.net/uploads/myvhd.vhd`.
47-
48-
```powershell
49-
$vhdUri = '<VHD URI>'
50-
```
59+
1. Set up the parameters.
5160

52-
1. Create the custom image by using the **New-AzResourceGroupDeployment** cmdlet. Replace the \<custom image name> and \<custom image description> placeholders with the name and description you want.
61+
- Replace the `<custom image name>` and `<custom image description` placeholders with a name and description for the custom image.
62+
- Replace the `<VHD URI>` placeholder with the URI of your uploaded VHD file. You can get the VHD file's URI from the Azure Storage container where you uploaded the file. An example VHD URI is: `https://acontosolab1234.blob.core.windows.net/uploads/myvhd.vhd`.
5363

5464
```powershell
5565
$customImageName = '<custom image name>'
5666
$customImageDescription = '<custom image description>'
67+
$vhdUri = '<VHD URI>'
5768
5869
$parameters = @{existingLabName="$($lab.Name)"; existingVhdUri=$vhdUri; imageOsType='windows'; isVhdSysPrepped=$false; imageName=$customImageName; imageDescription=$customImageDescription}
70+
```
5971

72+
1. Run [New-AzResourceGroupDeployment](/powershell/module/az.resources/new-azresourcegroupdeployment) to create the custom image by using a template according to the parameters.
73+
74+
```powershell
6075
New-AzResourceGroupDeployment -ResourceGroupName $lab.ResourceGroupName -Name CreateCustomImage -TemplateUri 'https://raw.githubusercontent.com/Azure/azure-devtestlab/master/samples/DevTestLabs/QuickStartTemplates/201-dtl-create-customimage-from-vhd/azuredeploy.json' -TemplateParameterObject $parameters
6176
```
6277

63-
## Complete PowerShell script
78+
## Use a PowerShell script
6479

65-
Combining the preceding steps produces the following PowerShell script that creates a custom image from a VHD file. To use the script, replace the following placeholders with your own values:
66-
67-
- \<subscription ID>
68-
- \<lab resource group name>
69-
- \<lab name>
70-
- \<VHD URI>
71-
- \<custom image name>
72-
- \<custom image description>
80+
You can combine the preceding steps to produce an Azure PowerShell script that creates a custom image from a VHD file. To use the script, replace the parameter values under the `# Values to change` comment with your own values.
7381

7482
```powershell
75-
# Log in to your Azure account.
76-
Connect-AzAccount
83+
# Values to change
84+
$subscriptionId = '<Azure subscription ID>'
85+
$labRg = '<Lab resource group name>'
86+
$labName = '<Lab name>'
87+
$vhdUri = '<VHD URI>'
88+
$customImageName = '<Name for the custom image>'
89+
$customImageDescription = '<Description for the custom image>'
7790
7891
# Select the desired Azure subscription.
79-
$subscriptionId = '<subscription ID>'
8092
Select-AzSubscription -SubscriptionId $subscriptionId
8193
8294
# Get the lab object.
83-
$labRg = '<lab resource group name>'
84-
$labName = '<lab name>'
8595
$lab = Get-AzResource -ResourceId ('/subscriptions/' + $subscriptionId + '/resourceGroups/' + $labRg + '/providers/Microsoft.DevTestLab/labs/' + $labName)
8696
87-
# Set the URI of the VHD file.
88-
$vhdUri = '<VHD URI>'
89-
90-
# Set the custom image name and description values.
91-
$customImageName = '<custom image name>'
92-
$customImageDescription = '<custom image description>'
93-
9497
# Set up the parameters object.
9598
$parameters = @{existingLabName="$($lab.Name)"; existingVhdUri=$vhdUri; imageOsType='windows'; isVhdSysPrepped=$false; imageName=$customImageName; imageDescription=$customImageDescription}
9699
97100
# Create the custom image.
98101
New-AzResourceGroupDeployment -ResourceGroupName $lab.ResourceGroupName -Name CreateCustomImage -TemplateUri 'https://raw.githubusercontent.com/Azure/azure-devtestlab/master/samples/DevTestLabs/QuickStartTemplates/201-dtl-create-customimage-from-vhd/azuredeploy.json' -TemplateParameterObject $parameters
99102
```
100103

101-
## Next steps
104+
## Related content
102105

103106
- [Compare custom images and formulas in DevTest Labs](devtest-lab-comparing-vm-base-image-types.md)
104107
- [Copying Custom Images between Azure DevTest Labs](https://www.visualstudiogeeks.com/blog/DevOps/How-To-Move-CustomImages-VHD-Between-AzureDevTestLabs#copying-custom-images-between-azure-devtest-labs)

0 commit comments

Comments
 (0)