Adding a Site Extension to an Azure Web App in an ARM template deployment

  • Azure
  • Devops

Azure Resource Manager (ARM) templates let you deploy and configure various Azure resources using a JSON file with a particular schema. Most of this schema is pretty easy to figure out from their documentation or by creating the resources in the Azure Portal and then using the "Automated Script" section of the resource group to look at what and how things were deployed.

One thing I haven't found great documentation on are Azure Web App Site Extensions. For example if I wanted to install the Composer Extension automatically when I deployed my web app. Here is what you need to know.

The ARM Template JSON

You need to add a resource to the resource section of your Azure Web App that has the site extension name. Just to make it clear in your ARM template you have a top level resources array and then within your Web App you can have another resources array. It is the array within the target web app you should add the following:

{
"apiVersion": "2015-08-01",
"name": "name-of-extension",
"type": "siteextensions",
"dependsOn": ["the-name-of-your-webapp"]
}

You need to replace the-name-of-your-webapp and name-of-extension with the appropriate values.

But how do I know the name-of-extension value? You look up the extension on the Site Extension Gallery and take the value that is in the URL on its home page. For example the Composer extension has the URL:

https://www.siteextensions.net/packages/ComposerExtension/

So the name is "ComposerExtension". An example of a web app with the composer:

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"siteName": {
"type": "string",
"defaultValue": "[resourceGroup().name]"
},
"appServicePlan": {
"type": "string",
"allowedValues": ["Free", "Shared", "Basic", "Standard", "Premium"],
"defaultValue": "Free"
}
},
"variables": {
"appServiceName": "[parameters('siteName')]",
"appName": "[parameters('siteName')]",
"configAppName": "[concat(parameters('siteName'), '/web')]"
},
"resources": [
{
"comments": "The App Service to host the Web App",
"type": "Microsoft.Web/serverfarms",
"sku": {
"name": "[parameters('appServicePlan')]"
},
"kind": "app",
"name": "[variables('appServiceName')]",
"apiVersion": "2015-08-01",
"location": "[resourceGroup().location]",
"scale": null,
"properties": {
"name": "[variables('appServiceName')]",
"numberOfWorkers": 0
},
"dependsOn": []
},
{
"comments": "The Web App",
"type": "Microsoft.Web/sites",
"kind": "app",
"name": "[variables('appName')]",
"apiVersion": "2015-08-01",
"location": "[resourceGroup().location]",
"properties": {
"name": "[variables('appName')]",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('appServiceName'))]"
},
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', variables('appServiceName'))]"
],
"resources": [
{
"apiVersion": "2015-08-01",
"name": "ComposerExtension",
"type": "siteextensions",
"dependsOn": ["[variables('appName')]"]
}
]
},
{
"comments": "The config for the Web App",
"type": "Microsoft.Web/sites/config",
"name": "[variables('configAppName')]",
"apiVersion": "2015-08-01",
"location": "[resourceGroup().location]",
"scale": null,
"properties": {
"localMySqlEnabled": true,
"numberOfWorkers": 1,
"netFrameworkVersion": "v4.0",
"phpVersion": "7.1",
"virtualApplications": [
{
"virtualPath": "/",
"physicalPath": "site\\wwwroot",
"preloadEnabled": false,
"virtualDirectories": null
}
],
"defaultDocuments": ["index.php"]
},
"dependsOn": ["[resourceId('Microsoft.Web/sites', variables('appName'))]"]
}
]
}