Blog

Conditional parts in ARM Templates

Peter Groenewegen

Updated April 30, 2025
2 minutes

When creating reusable ARM templates you have a number of options on how to manage conditional parts in your templates. The smallest conditions can be done by parameters, medium differences can be done by  t-shirt sizes and large differences by linked templates. In this blog post I’ll show how to use implement conditions by linked templates. Making conditions with linked templates From one template in resource manager you can link to an other template. This enables you to decompose a large template into smaller more maintainable templates. The linking is done by the template type Microsoft.Resources/deployments. This template contains a property templateLink with the uri to the actual template.

"resources": [
  {
      "apiVersion": "2015-01-01",
      "name": "linkedTemplate",
      "type": "Microsoft.Resources/deployments",
      "properties": {
        "mode": "incremental",
        "templateLink": {
          "uri": "https://www.contoso.com/AzureTemplates/newStorageAccount.json",
          "contentVersion": "1.0.0.0"
        },
        "parameters": {
          "StorageAccountName":{"value": "[parameters('StorageAccountName')]"}
        }
      }
  }
]

By making the uri changeable you can chose on which template you want to load. The uri can be a variable that you compose base on a given parameter. A simple example can be:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters":{
       "condition":{
          "type":"string",
          "allowedValues":{
              "option1",
              "option2"
          }
       },
       ...
    },
    "variables":{
        "conditionaluri":"[concat('https://www.contoso.com/AzureTemplates/newStorageAccount',parameters('condition'),'.json')]",
...
    }
    "resources": [
      {
          "apiVersion": "2015-01-01",
          "name": "linkedTemplate",
          "type": "Microsoft.Resources/deployments",
          "properties": {
            "mode": "incremental",
            "templateLink": {
              "uri": "[variables('conditionaluri')]",
              "contentVersion": "1.0.0.0"
            },
            "parameters": {
              "StorageAccountName":{"value": "[parameters('StorageAccountName')]"}
            }
          }
      }
    ]
}

In this template the parameter condition will choose between the uri’s:

Both templates can contain different implementations of the StorageAccount template. This technique can be used on all conditions you want to implement into your templates. It can be applied on multiple levels in your linked template tree.

Written by

Peter Groenewegen

Our Ideas

Explore More Blogs

View All

Deep Knowledge

Deep Knowledge

Deepanshu Garg


FAQ Test BE Puneet Blog updated 102 22 j

FAQ Test BE Puneet Blog updated 102 22 j

Puneet Pathak, Bryan van Schaijk, Deepanshu Garg, Ellis van der Slikke, Jake Richardson


test44

test44

Puneet Pathak, Bartlo Mie, Deepanshu Garg, Adam23172 Rzymowski23172, Anna Małek


Blog 2

Blog 2

Puneet Pathak

Contact

Let’s discuss how we can support your journey.