Configure application settings for Azure Web App using Azure ARM template

In last post, we have discussed how to create azure web app along with the deployment slots using Azure ARM template. We are going to expand on the template created and learn how to configure application settings, web app properties like alwaysOn, remote debugging, etc and connection strings for azure web app in this blog post.

Define Web App Properties

Method 1: Use of Object variables
Variables are not only useful for declaring text that is used in multiple places and standardize them; they can be objects as well. This is especially handy in case you want to create multiple web apps in your template and apply common settings to them all.

Below is one of the sample code we can use:

ARM code to define object type variable
ARM code to define object type variable

Now, we need to associate the properties with web app and also to the deployment slot. For that, we can simple go to the resources array and add below code:

ARM code to apply application configuration from variables
ARM code to apply application configuration from variables

Note that the code will vary a little for slot configuration, as it needs to be altered to suit to its parent. Below snip shows application settings will look like once you deploy web app using above code:

Application settings from azure portal after deployment of arm template
Application settings from azure portal after deployment of arm template

Method 2: Use of Object parameters
Not only variables but parameters can have a object type too. This is very useful to apply multiple settings for a particular web application. It is most commonly use to deploy connection strings and application settings. Again, you can define properties like alwaysOn, remote debugging etc by making use of parameters, instead of variables as well. One of the examples of using object parameters is discussed as below where we define application and connection strings.

Define Application Settings and Connection Strings

Since application settings are specific to a web app, we would generally make use of a object parameter type as mentioned above. First, let’s define a complex parameter type in main resource definition file:

ARM code to define object type parameter
ARM code to define object type parameter

And define its value within parameters file:

ARM code for defining web app application settings
ARM code for defining web app application settings

Once its done, let’s do association for web application using below code:

ARM Code to define application settings and connecting strings
ARM Code to define application settings and connecting strings

Again, to deploy same settings for slot would require a slightly different code.
Below is a sample of settings after deployment:

Application settings from azure portal - 2
Application settings from azure portal – 2

Below is a full copy of the ARM template:


{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appServiceName": {
"type": "string",
"minLength": 1
},
"appServiceSkuName": {
"type": "string",
"defaultValue": "F1",
"allowedValues": [
"F1",
"D1",
"B1",
"B2",
"B3",
"S1",
"S2",
"S3",
"P1",
"P2",
"P3",
"P4"
],
"metadata": {
"description": "Describes plan's pricing tier and capacity. Check details at https://azure.microsoft.com/en-us/pricing/details/app-service/"
}
},
"webAppName": {
"type": "string",
"minLength": 1
},
"stagingSlotName": {
"type": "string",
"minLength": 1
},
"webApplicationSettings": {
"type": "object"
}
},
"variables": {
"siteProperties": {
"netFrameworkVersion": "v4.7", // Defines dont net framework version
"use32BitWorkerProcess": false, // 64-bit platform
"webSocketsEnabled": true,
"alwaysOn": true, // Always On
"requestTracingEnabled": true, // Failed request tracing, aka 'freb'
"httpLoggingEnabled": true, // IIS logs (aka Web server logging)
"logsDirectorySizeLimit": 40, // 40 MB limit for IIS logs
"detailedErrorLoggingEnabled": true, // Detailed error messages
"remoteDebuggingEnabled": true, // enables remote debugging
"remoteDebuggingVersion": "VS2013",
"defaultDocuments": [
"home.html"
]
}
},
"resources": [
{
"name": "[parameters('appServiceName')]",
"type": "Microsoft.Web/serverfarms",
"location": "[resourceGroup().location]",
"apiVersion": "2015-08-01",
"sku": {
"name": "[parameters('appServiceSkuName')]"
},
"dependsOn": [ ],
"tags": {
"displayName": "appService"
},
"properties": {
"name": "[parameters('appServiceName')]",
"numberOfWorkers": 1
}
},
{
"name": "[parameters('webAppName')]",
"type": "Microsoft.Web/sites",
"location": "[resourceGroup().location]",
"apiVersion": "2015-08-01",
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', parameters('appServiceName'))]"
],
"tags": {
"[concat('hidden-related:', resourceId('Microsoft.Web/serverfarms', parameters('appServiceName')))]": "Resource",
"displayName": "webApp"
},
"properties": {
"name": "[parameters('webAppName')]",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('appServiceName'))]"
},
"resources": [
{
"apiVersion": "2015-08-01",
"name": "web",
"type": "config",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', parameters('webAppName'))]"
],
"properties": "[variables('siteProperties')]"
},
{
"apiVersion": "2015-08-01",
"location": "[resourceGroup().location]",
"type": "config",
"name": "connectionstrings",
"dependsOn": [
"[concat('Microsoft.Web/sites/', parameters('webAppName'))]"
],
"properties": "[parameters('webApplicationSettings').connectionStrings.prod]"
},
{
"apiVersion": "2015-08-01",
"location": "[resourceGroup().location]",
"type": "config",
"name": "appsettings",
"dependsOn": [
"[concat('Microsoft.Web/sites/', parameters('webAppName'))]"
],
"properties": "[parameters('webApplicationSettings').appSettings.prod]"
},
{
"apiVersion": "2015-08-01",
"name": "slotconfignames",
"type": "config",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', parameters('webAppName'))]"
],
"properties": {
"appSettingNames": "[ parameters('webApplicationSettings').appSettings.stickySettings ]",
"connectionStringNames": "[ parameters('webApplicationSettings').connectionStrings.stickySettings ]"
}
},
{
"apiVersion": "2015-08-01",
"name": "[parameters('stagingSlotName')]",
"type": "slots",
"tags": {
"displayName": "webAppSlots"
},
"location": "[resourceGroup().location]",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', parameters('webAppName'))]"
],
"properties": {
},
"resources": [
{
"apiVersion": "2015-08-01",
"name": "web",
"type": "config",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites/Slots', parameters('webAppName'),parameters('stagingSlotName'))]"
],
"properties": "[variables('siteProperties')]"
},
{
"apiVersion": "2015-08-01",
"location": "[resourceGroup().location]",
"type": "config",
"name": "connectionstrings",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites/Slots', parameters('webAppName'),parameters('stagingSlotName'))]"
],
"properties": "[parameters('webApplicationSettings').connectionStrings.prod]"
},
{
"apiVersion": "2015-08-01",
"location": "[resourceGroup().location]",
"type": "config",
"name": "appsettings",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites/Slots', parameters('webAppName'),parameters('stagingSlotName'))]"
],
"properties": "[parameters('webApplicationSettings').appSettings.prod]"
},
{
"apiVersion": "2015-08-01",
"name": "slotconfignames",
"type": "config",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites/Slots', parameters('webAppName'),parameters('stagingSlotName'))]"
],
"properties": {
"appSettingNames": "[ parameters('webApplicationSettings').appSettings.stickySettings ]",
"connectionStringNames": "[ parameters('webApplicationSettings').connectionStrings.stickySettings ]"
}
}
]
}
]
}
],
"outputs": {}
}

2 thoughts on “Configure application settings for Azure Web App using Azure ARM template

  1. “slotconfignames” should only be specified on production slot to tell which settings that are slot specific even if they don´t even exist on the production slot. The actual value for the slot specific setting should still be specified on the slot settings. Here is my comment on StackOverflow. https://stackoverflow.com/a/51873013/5023367

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s