Nested Arm Templates

Nested Arm Templates

2021, Mar 29    

The awful problem with NULL Resource Groups.

I’ve run into an issue when creating Nested Arm templates that use Storage Accounts and dependant services. It centers around a Subscription level deployment, which first creates a Resource Group that the other template(s) depend on.

The error is reporting a NULL on the resource group;

Status Message: The Resource 'Microsoft.Storage/storageAccounts/yourstorageaccount' under resource group '<null>' was not found. 
For more details please go to https://aka.ms/ARMResourceNotFoundFix (Code:ResourceNotFound)

Essentially i have two templates

  1. Deploy Resource Group
  2. Deploy Storage / App Service Plan / FunctionApp

Run separately, they both work great…. Push them together to be nested, and the problems start… Which is odd as validation of the template itself has already happened.

A great deal of debugging later, and the problem centers around the scope of the nested deployment. Specifically by adding a property to my deployment to force Inner scope, then my template started working as expected.

Ultimately by functioning in a Inner Scope, you need to explicitly specific input parameters to your tested template, and then explicitly pass those parameters as part of the deployment… So we’re adding a little work for ourself to get to the solution.

    "expressionEvaluationOptions": {
        "scope": "inner"
    },

You can read more about Arm template Scopes here https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/scope-functions?tabs=azure-powershell#function-resolution-in-scopes

Examples of working templates.

Here’s my full working script of a Resource Group, Storage, App Service Plan, Function App, and code : https://github.com/Gordonby/Snippets/blob/master/AzureDevOps/PR-Check-Gate/arm-deploy-function-wResourceGroup.json

Here’s a few simpler examples of nested templates : https://github.com/Gordonby/Snippets/tree/master/ArmTemplates