Proposed Pull Request Change

title description ms.topic ms.date
Deploy a template spec as a linked template Learn how to deploy an existing template spec in a linked deployment. how-to 10/29/2025
📄 Document Links
GitHub View on GitHub Microsoft Learn View on Microsoft Learn
Raw New Markdown
Generating updated version of doc...
Rendered New Markdown
Generating updated version of doc...
+0 -0
+0 -0
--- title: Deploy a template spec as a linked template description: Learn how to deploy an existing template spec in a linked deployment. ms.topic: how-to ms.date: 10/29/2025 --- # Tutorial: Deploy a template spec as a linked template Learn how to deploy an existing [template spec](template-specs.md) by using a [linked deployment](linked-templates.md#linked-template). Use template specs to share ARM templates with other users in your organization. After you create a template spec, you can deploy it by using Azure PowerShell or Azure CLI. You can also deploy the template spec as part of your solution by using a linked template. ## Prerequisites An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/pricing/purchase-options/azure-account?cid=msft_learn). > [!NOTE] > To use template spec with Azure PowerShell, you must install [version 5.0.0 or later](/powershell/azure/install-azure-powershell). To use it with Azure CLI, use [version 2.14.2 or later](/cli/azure/install-azure-cli). ## Create a template spec To create a template spec for deploying a storage account, see [Quickstart: Create and deploy template spec](quickstart-create-template-specs.md). You need the resource group name of the template spec, template spec name, and template spec version for the next section. ## Create the main template To deploy a template spec in an ARM template, add a [deployments resource](/azure/templates/microsoft.resources/deployments) to your main template. In the `templateLink` property, specify the resource ID of a template spec. Create a template with the following JSON called **azuredeploy.json**. This tutorial assumes you saved the template to **c:\Templates\deployTS\azuredeploy.json** but you can use any path. ```json { "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "location": { "type": "string", "defaultValue": "[resourceGroup().location]" }, "tsResourceGroup":{ "type": "string", "metadata": { "Description": "Specifies the resource group name of the template spec." } }, "tsName": { "type": "string", "metadata": { "Description": "Specifies the name of the template spec." } }, "tsVersion": { "type": "string", "defaultValue": "1.0.0.0", "metadata": { "Description": "Specifies the version the template spec." } }, "storageAccountType": { "type": "string", "defaultValue": "Standard_LRS", "metadata": { "Description": "Specifies the storage account type required by the template spec." } } }, "variables": { "appServicePlanName": "[concat('plan', uniquestring(resourceGroup().id))]" }, "resources": [ { "type": "Microsoft.Web/serverfarms", "apiVersion": "2025-03-01", "name": "[variables('appServicePlanName')]", "location": "[parameters('location')]", "sku": { "name": "B1", "tier": "Basic", "size": "B1", "family": "B", "capacity": 1 }, "kind": "linux", "properties": { "perSiteScaling": false, "reserved": true, "targetWorkerCount": 0, "targetWorkerSizeId": 0 } }, { "type": "Microsoft.Resources/deployments", "apiVersion": "2025-04-01", "name": "createStorage", "properties": { "mode": "Incremental", "templateLink": { "id": "[resourceId(parameters('tsResourceGroup'), 'Microsoft.Resources/templateSpecs/versions', parameters('tsName'), parameters('tsVersion'))]" }, "parameters": { "storageAccountType": { "value": "[parameters('storageAccountType')]" } } } } ], "outputs": { "templateSpecId": { "type": "string", "value": "[resourceId(parameters('tsResourceGroup'), 'Microsoft.Resources/templateSpecs/versions', parameters('tsName'), parameters('tsVersion'))]" } } } ``` The template spec ID is generated by using the [`resourceID()`](template-functions-resource.md#resourceid) function. The resource group argument in the `resourceID()` function is optional if the template spec is in the same resource group of the current deployment. You can also directly pass in resource ID as a parameter. To get the ID, use: # [PowerShell](#tab/azure-powershell) ```azurepowershell-interactive $id = (Get-AzTemplateSpec -ResourceGroupName $resourceGroupName -Name $templateSpecName -Version $templateSpecVersion).Versions.Id ``` # [CLI](#tab/azure-cli) ```azurecli-interactive id = $(az ts show --name $templateSpecName --resource-group $resourceGroupName --version $templateSpecVersion --query "id") ``` > [!NOTE] > There's a known issue with getting a template spec ID and assigning it to a variable in Windows PowerShell. --- The syntax for passing parameters to the template spec is: ```json "parameters": { "storageAccountType": { "value": "[parameters('storageAccountType')]" } } ``` > [!NOTE] > The apiVersion of `Microsoft.Resources/deployments` must be 2020-06-01 or later. ## Deploy the template When you deploy the linked template, it deploys both the web application and the storage account. The deployment is same as deploying other ARM templates. # [PowerShell](#tab/azure-powershell) ```azurepowershell New-AzResourceGroup ` -Name webRG ` -Location westus2 New-AzResourceGroupDeployment ` -ResourceGroupName webRG ` -TemplateFile "c:\Templates\deployTS\azuredeploy.json" ` -tsResourceGroup templateSpecRg ` -tsName storageSpec ` -tsVersion 1.0 ``` # [CLI](#tab/azure-cli) ```azurecli az group create \ --name webRG \ --location westus2 az deployment group create \ --resource-group webRG \ --template-file "c:\Templates\deployTS\azuredeploy.json" \ --parameters tsResourceGroup=templateSpecRG tsName=storageSpec tsVersion=1.0 ``` --- ## Next steps To learn about creating a template spec that includes linked templates, see [Create a template spec of a linked template](template-specs-create-linked.md).
Success! Branch created successfully. Create Pull Request on GitHub
Error: