Azure ARM Linked Templates and Complete mode

Just a small blog post on Azure ARM Linked Template deployment and Complete mode since I couldn’t find a satisfying answer quickly enough via my favorite search engine.

TL;DR: Linked Template resources together with the master template resources are deployed / kept / updated. Resources out of the cumulative result of master + linked templates are deleted.

Today I was wondering what would happen if I had a “master” template being deployed in complete mode, what would happen if it had Linked template deployments.

I have this sample “master” deployment template:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {},
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Storage/storageAccounts",
            "apiVersion": "2018-07-01",
            "name": "bgelensst01",
            "location": "[resourceGroup().location]",
            "sku": {
                "name":"Standard_LRS"
            }
        },
        {
            "name": "createsecond",
            "type": "Microsoft.Resources/deployments",
            "apiVersion": "2015-01-01",
            "properties": {
                "mode": "Incremental",
                "templateLink": {
                    "uri": "https://boguslink/storage.json",
                    "contentVersion": "1.0.0.0"
                }
            }
        }
    ],
    "outputs": {}
}

Note that it is only supported to have Incremental mode specified for Linked deployements.

The linked storage.json looks like this:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {},
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Storage/storageAccounts",
            "apiVersion": "2018-07-01",
            "name": "bgelensst02",
            "location": "[resourceGroup().location]",
            "sku": {
                "name":"Standard_LRS"
            }
        }
    ],
    "outputs": {}
}

I created a resource group called complete and deployed the template to it using PowerShell:

New-AzResourceGroupDeployment -ResourceGroupName complete -TemplateFile .\azuredeploy.1.json -Mode Complete -Force

completedeploy01

The result is 2 Storage Accounts. So no problem there even though you might think to have a conflicting situation with the Linked deployment being in incremental mode.

resultcomplete01

Now let’s add another resource to the resource group which is not specified in one of templates.

completewithnsg

I’ve added a NSG. Let’s do another deployment of the master template in complete mode and check the result.

New-AzResourceGroupDeployment -ResourceGroupName complete -TemplateFile .\azuredeploy.1.json -Mode Complete -Force

The NSG is removed but the storage accounts remained. When checking the related events we find the delete operation of the NSG.

completeactivity

To summarize, Linked Template resources together with the master template resources are deployed / kept / updated. Resources out of the cumulative result of master + linked templates are deleted.

comments powered by Disqus