Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /var/www/rassie.dk/blog.rassie.dk/wp-content/themes/suffusion/functions/media.php on line 666
TIL about Azure Resource Manager templates | Rasmus' Ramblings on IT and other stuff
Sep 292017
 

I recently wanted to create an Azure Resource Manager (ARM) template with a number of interdependent resources. This post contains a number of “Things I Learned”. Hopefully, you can avoid some of the problems I had.

The resources were:

  • SQL server and database
  • Azure function app
  • Azure web app for an ASP.NET Core site
  • Storage account
  • Application Insights instance for the web app
  • Application Insights instance for the function app

In my previous post I described a place to get detailed logs about Web App site extension installation. I had spent a long time to figure out the reason that the installation of the Application Insights site extension failed.

With the new detailed log information – which was nowhere in the Azure Portal or in the output from the New-AzureRMResourceGroupDeployment Powershell cmd-let – I found the most likely cause of the installation problem: The web app was being restarted while the site extension was being installed. It would be really nice, if the ThreadAbortException had been more visible, it was very googleable, and I found the cause of the problem in short order.

It apparently only affected the Application Insights site extension, because it takes a while (about a minute and a half on the S1 App Service Plan). The .NET Core site extension which the template also installed never failed.

In the end, I solved the problem by adding dependencies between the resources, until I had a dependency chain that worked.

I used the Azure Resource Manager Template Visualizer (ARMViz) to display and edit the inter-dependencies until it succeeded.

In the end, ARMViz also found some issues with the template, that the Powershell cmd-let and VS Code (my editor for this), hadn’t shown. For example: JSON doesn’t have comments with //, and one place, I had a comma after the final property in an object. Not big stuff, but still important, as it broke ARMViz (because it is stricter than the two others), and who knows how Azure reacted to those minor issues.

ARMViz can display relationships between resources as they are defined in the template like this:

ARM visualization

Unfortunately, it doesn’t support all resource types. For example, the site extensions aren’t displayed, but it helped immensely.

Another thing I found during my template debugging and attempting to run the deployment is that it takes a really long time to delete Azure Resource Groups with resources inside them. And even if you cancel a deployment from the Azure Portal, the resources that have been queued for creation will still be created.

In the end, the fastest way to run the deployment after making changes to my template, was to simply run the deployments on the same resource group, where I pre-pended the resource names with a running identifier, e.g.

New-AzureRmResourceGroupDeployment 
 	-ResourceGroupName RWTest 
 	-TemplateFile .\Template.json 
 	-EnvironmentNameAbbreviation rwt7 
 	-Name rwt7

The EnvironmentNameAbbreviation parameter is an ARM template parameter, which is defined in the template file like this:

"parameters": {
    "EnvironmentNameAbbreviation": {
      "defaultValue": "rwtest",
      "type": "string"
    }    
  }

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)