PAAS Sitecore 9 with an ASE ARM template errors

Sitecore 9 works great in PAAS and the arm templates are an enormous help. However if you’re like me and need to use an ASE then you find that your deployments are regularly and mysteriously failing. I poured over the arm templates searching for any reason that this might be happening. After about a month i accepted the unfortunate truth that Azure was incorrectly reporting success before it should.

I started pulling apart the templates searching for more information. I utilized a custom powershell containment system to manage the ARM template parameters

The errors originated from the application deployments. These are the parts that use web deploy to restore databases, create users, and push files to your Sitecore server.

How to stabilize the arm templates

For this i will assume that you’ve already added the hostingEnvironmentProfile parameter to the Microsoft.Web/sites ARM resources
Warning: this process is very time consuming
The first step is to pull them apart. I was able to achieve a high success rate by doing the following:

  1. Take the main azuredeploy.json and remove all of the resources, we’re going to be manually executing them
  2. In each of the nested ARM template json make sure that the required parameters are defined in the parameters and variables section, you can refer back to the azuredeploy.json for how these should be setup
  3. The application.json file is the primary culprit that’s causing our failures, we need to split this one up just like we did the azuredeploy.json except this time we’re going to be creating new ARM template json files for each of the 4 web deploy deployments that reside in application.json
  4. Now that we have the ARM templates separated out into their individual parts we need to create a new powershell wrapper for the process
  5. Note, for security reasons i’m largely omitting things of a sensitive nature here. Make sure you apply user names and passwords to your input parameters either in a parameters.json or in the parameters powershell hashtable as described below

    Powershell Magic

    You can find the scripts Here

    Due to the lack of a central ARM template to orchestrate parameters we need to do that ourselves, this comes in a few steps

    1. populate all starting parameters in a hashtable. see Execute.ps1 for an example. Note that you will need to pass in several more parameters or you can include them in a parameters.json that’s loaded here
    2. Scan the arm templates and gather their accepted parameters as they won’t take any extra. See Get-ValidParameters in Utilities.ps1
    3. Based on each ARM template gather up the parameters needed for the deployment and generate a new hashtable of parameters and their values. See Get-Parameters in Utilities.ps1
    4. Execute ARM template using a modified version of Sitecore’s ARM template execution code. See Start-SitecoreAzureDeployment in Utilities.ps1
    5. After completion extract out populated parameters and outputs and save them using Get-ValidParameters from Utilities.ps1
    6. repeat until finished. You can see how the arm templates are ordered here.
      Note, depending on your specific case, you may need to adjust some timing between deployments if some deployments need more time to settle