Azure Web App Sticky Settings Simplified
If you’ve navigated to this article, I trust you already know what Azure Web App slot settings (aka sticky) settings are ;)
I’m also assuming you are on the same boat I was not too long ago. That is, wondering why there’s little to none clearly documented ways to deploy Azure Web Apps alongside sticky settings, via bicep templates.
As such, to save the next person some time, I decided to create this quick how-to. I hope it saves you time.
Happy coding!
TL’DR
The Microsoft.Web sites/config ‘slotConfigNames’ resource has a string array
property called appSettingNames
. ALL slots' settings are scanned and matched against this array. Matches produce sticky settings.
For example:
- Production slot settings:
{ DB: 'prod-db', FOO: 'bar' }
- Staging slot settings:
{ DB: 'stg-db', BAZ: 'qux' }
- SlotConfigNames:
[ 'DB', 'BAZ' ]
- Result:
DB
sticky inprod
andstg
slots,BAZ
sticky instg
slot
Bicep Sample
param location string = resourceGroup().location
resource appServicePlan 'Microsoft.Web/serverfarms@2022-09-01' = {
// omitted for breveity
}
var webAppProperties = {
// omitted for brevity
}
// Deployed to the staging slot, and eventually swapped to the production slot, NOT STICKY!
var webAppSettings = {
DOTNET_ENVIRONMENT: 'Demo'
}
var webAppStickySettings = {
productionSlot: {
DB: 'prod-db'
FOO: 'bar'
}
stagingSlot: {
DB: 'staging-db'
BAZ: 'qux'
}
}
// In this example: [ 'FOO', 'DB', 'BAZ' ]
var webAppStickySettingsKeys = [for setting in items(union(webAppStickySettings.productionSlot, webAppStickySettings.stagingSlot)): setting.key]
resource webApp 'Microsoft.Web/sites@2022-09-01' = {
// Production slot
name: 'sample-webapp'
location: location
properties: webAppProperties
resource appsettings 'config' = { name: 'appsettings', properties: webAppStickySettings.productionSlot /* Only prod slot sticky settings, other settings will arrive after staging slot swap */ }
// Staging slot
resource stagingSlot 'slots' = {
name: 'staging'
location: location
properties: webAppProperties
resource appsettings 'config' = { name: 'appsettings', properties: union(webAppSettings, webAppStickySettings.stagingSlot) }
}
// Sticky settings
// Note: although this resource is a direct child of the webApp's production slot, this config applies to both the production and staging slots
// This config simply matches the appSettingNames of the webApp's production slot AND staging slot
// For all matches, it will mark the appSetting as sticky
resource slotsettings 'config' = {
name: 'slotConfigNames'
properties: {
appSettingNames: webAppStickySettingsKeys // in this example: [ 'FOO', 'DB', 'BAZ' ]
}
}
}