Edit

Share via


Nested templates in DevTest Labs environments

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.

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.

For general information about nested templates, including code samples, see Use linked and nested templates when deploying Azure resources.

Note

Azure Deployment Environments (ADE) is highly recommended for creating environments. ADE empowers developers to rapidly deploy app infrastructure using project-based templates, ensuring consistent and secure environments for your development teams.

To learn more about Azure Deployment Environments, see Azure Deployment Environments documentation.

Nested template deployment

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.

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.

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.

Nested template example

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.

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.


"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
    "_artifactsLocation": {
        "type": "string"
    },
    "_artifactsLocationSasToken": {
        "type": "securestring"
    }},
"variables": {
    "NestOneTemplateFolder": "nestedtemplates",
    "NestOneTemplateFileName": "NestOne.json",
    "NestOneTemplateParametersFileName": "NestOne.parameters.json"},
    "resources": [
    {
        "name": "NestOne",
        "type": "Microsoft.Resources/deployments",
        "apiVersion": "2016-09-01",
        "dependsOn": [ ],
        "properties": {
            "mode": "Incremental",
            "templateLink": {
                "uri": "[concat(parameters('_artifactsLocation'), '/', variables('NestOneTemplateFolder'), '/', variables('NestOneTemplateFileName'), parameters('_artifactsLocationSasToken'))]",
                "contentVersion": "1.0.0.0"
            },
            "parametersLink": {
                "uri": "[concat(parameters('_artifactsLocation'), '/', variables('NestOneTemplateFolder'), '/', variables('NestOneTemplateParametersFileName'), parameters('_artifactsLocationSasToken'))]",
                "contentVersion": "1.0.0.0"
            }
        }    
    }],
"outputs": {}