Tutorial: Create a template spec with linked templates
Grein
Learn how to create a template spec with a main template and a linked template. You use template specs to share ARM templates with other users in your organization. This article shows you how to create a template spec to package a main template and its linked templates using the relativePath property of the deployment resource.
To link a template, add a deployments resource to your main template. In the templateLink property, specify the relative path of the linked template in accordance with the path of the parent template.
The linked template is called linkedTemplate.json, and is stored in a subfolder called artifacts in the path where the main template is stored. You can use one of the following values for the relativePath:
./artifacts/linkedTemplate.json
/artifacts/linkedTemplate.json
artifacts/linkedTemplate.json
The relativePath property is always relative to the template file where relativePath is declared, so if there is another linkedTemplate2.json that is called from linkedTemplate.json and linkedTemplate2.json is stored in the same artifacts subfolder, the relativePath specified in linkedTemplate.json is just linkedTemplate2.json.
Create the main template with the following JSON. Save the main template as azuredeploy.json to your local computer. This tutorial assumes you've saved to a path c:\Templates\linkedTS\azuredeploy.json but you can use any path.
Save the template as linkedTemplate.json in the artifacts folder.
Create template spec
Templates specs are stored in resource Groups. Create a resource group, and then create a template spec with the following script. The template spec name is webSpec.
az ts show --name webSpec --resource-group templateSpecRG --version"1.0.0.0"
Deploy template spec
You can now deploy the template spec. Deploying the template spec is just like deploying the template it contains, except that you pass in the resource ID of the template spec. You use the same deployment commands, and if needed, pass in parameter values for the template spec.
az group create \
--name webRG \
--location westus2
id = $(az ts show --name webSpec --resource-group templateSpecRG --version"1.0.0.0"--query"id")
az deployment group create \
--resource-group webRG \
--template-spec$id
Athugasemd
There is a known issue with getting a template spec ID and assigning it to a variable in Windows PowerShell.
Build end-to-end solutions in Microsoft Azure to create Azure Functions, implement and manage web apps, develop solutions utilizing Azure storage, and more.
Describes recommended approaches for authoring Azure Resource Manager templates (ARM templates). Offers suggestions to avoid common problems when using templates.