DevOps with Sitecore on Azure Part 1 - Deploying into an App Service Environment

DevOps with Sitecore on Azure Part 1 - Deploying into an App Service Environment

This blog post is the fist of two posts with tips and tricks about running Sitecore on Azure PaaS services. Today I will show you how you can deploy Sitecore 9 to an App Service Environment (ASE).

App Service Environment

The ARM templates that are provided by Sitecore, through their Github repo, deploy Sitecore on so-called multi-tenant App Services. With a few modifications to these templates you can deploy the Sitecore App Service Plans to an App Service Environment. This provides network isolation, connections to on-premises systems through Express Route and more.

The modifications that I describe in this post should work for all Sitecore 9.x configurations. Please note, the ASE must already exist for this to work.

parameters.json file

I begin by defining two parameters in the azuredeploy.parameters.json file, called "aseName" and "aseResourceGroupName". The first specifies the name of the ASE and the second specifies the Resource Group name that the ASE resides in.

1"aseName": {
2    "value": "myDummyAse"
4"aseResourceGroupName": {
5    "value": "myAseRg"

azuredeploy.json file

The azuredeploy.json file doesn't create any Azure resources itself. It functions as the main template from which linked or nested templates are deployed. We need to make a few modifications to this template.

Step 1: Define the two parameter we just create in the parameters section of the template.

 1"aseName": {
 2    "type": "string",
 3    "metadata": {
 4    "description": "Name of the App Service Environment"
 5    }
 7"aseResourceGroupName": {
 8    "type": "string",
 9    "metadata": {
10    "description": "Name of the resource group that the ASE resides in."
11    }

Step 2: Add the parameter to the resource where the nested infrastructure.json template is referenced: "[concat(parameters('deploymentId'), '-infrastructure')]"

 1"resources": [
 3    "apiVersion": "[variables('resourcesApiVersion')]",
 4    "name": "[concat(parameters('deploymentId'), '-infrastructure')]",
 5    "type": "Microsoft.Resources/deployments",
 6    "properties": {
 7    "mode": "Incremental",
 8    "templateLink": {
 9        "uri": "[concat(uri(parameters('templateLinkBase'), 'nested/infrastructure.json'), parameters('templateLinkAccessToken'))]"
10    },
11    "parameters": {
12        "deploymentId": {
13        "value": "[parameters('deploymentId')]"
14        },
15        "location": {
16        "value": "[parameters('location')]"
17        },
19        "aseName": {
20        "value": "[parameters('aseName')]"
21        },
22        "aseResourceGroupName": {
23        "value": "[parameters('aseResourceGroupName')]"
24        },

Step 3: Add the parameter to the other infrastructure template references, like  -infrastructure-exm.json or -infrastructure-ma.json. Which infrastructure template resources are in the file depends on the Sitecore topology that you are deploying.

For each of the infrastructure template resources, add the parameter exactly the same as in Step 2.

infrastructure.json file

Step 1: Add the parameters "aseName" and "aseResourceGroupName"to the parameter section, just like you did in Step 1 of the azuredeploy.json.

Step 2: Change the properties of the "Microsoft.Web/serverfarms" resouces. Simply do a search for all resources of type "Microsoft.Web/serverfarms" and make sure the hostingEnvironment and hostingEnvironmentId properties are configured as below.

 2    "type": "Microsoft.Web/serverfarms",
 3    "name": "[variables('singleHostingPlanNameTidy')]",
 4    "apiVersion": "[variables('serverFarmApiVersion')]",
 5    "sku": {
 6    "name": "[parameters('singleHostingPlanSkuName')]",
 7    "capacity": "[parameters('singleHostingPlanSkuCapacity')]"
 8    },
 9    "properties": {
10    "name": "[variables('singleHostingPlanNameTidy')]",
11    "hostingEnvironment": "[parameters('aseName')]",
12    "hostingEnvironmentId": "[resourceId(parameters('aseResourceGroupName'),'Microsoft.Web/hostingEnvironments', parameters('aseName'))]"        
13    },
14    "location": "[parameters('location')]",
15    "tags": {
16    "provider": "[variables('sitecoreTags').provider]",
17    "logicalName": "[variables('sitecoreTags').single]"
18    }

Other infrastructure files

Depending on the Sitecore configuration you are deploying, you need to repeat the steps listed in infrastructure.json for othter templates. For example, when you are deploying the Sitecore XP Scaled configuration, you also need to modify the files infrastructure-exm.json, infrastructure-ma.json and infrastructure-xc.json.

Simply look inside the /nested folder and change all the templates that contain the term "infrastructure" and where resources are created of type Microsoft.Web/serverfarms.

More information

Check out my Github repository to find an example of an XP Single setup in an App Service Environment.

I would also highly recommend the "Sitecore 9.0.1 on Azure: PaaS Deployment Guide" article by Pete Navarra, where he explains how to get started with deploying Sitecore on Azure.