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
#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.
9
11
---
10
12
11
-
# Deploy DevTest Labs environments by using nested templates
13
+
# Nested templates in DevTest Labs environments
12
14
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.
14
16
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.
16
18
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).
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
29
24
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.
31
26
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.
33
28
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).
35
30
36
-

31
+
## Nested template example
37
32
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.
39
34
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.
41
36
42
37
```json
43
38
@@ -75,7 +70,7 @@ The following example shows the main *azuredeploy.json* ARM template file for th
75
70
"outputs": {}
76
71
```
77
72
78
-
## Next steps
73
+
## Related content
79
74
80
75
- 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).
#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.
9
11
---
10
12
11
-
# Create a custom image from a VHD file with PowerShell
13
+
# Create a custom image from a VHD file by using Azure PowerShell
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).
-**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).
20
25
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.
22
28
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:
24
30
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**.
26
33
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)
30
39
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.
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.
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.
51
60
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`.
1. Run [New-AzResourceGroupDeployment](/powershell/module/az.resources/new-azresourcegroupdeployment) to create the custom image by using a template according to the parameters.
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.
73
81
74
82
```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>'
0 commit comments