Reputation: 3746
How to stick app config settings to a slot via bicep?
Here is my bicep file:
var stagingSettings = [
{
name: 'AzureFunctionsJobHost__extensions__durableTask__hubName'
value: 'staging'
slotSetting: true
}
]
resource functionApp 'Microsoft.Web/sites/slots@2018-11-01' = {
name: name
kind: kind
location: location
properties: {
clientAffinityEnabled: true
enabled: true
httpsOnly: true
serverFarmId: resourceId('Microsoft.Web/serverfarms', servicePlanName)
siteConfig: {
use32BitWorkerProcess : false
appSettings: stagingSettings
}
}
identity: {
type: 'SystemAssigned'
}
}
On deploying this code, I don't see app config settings stick to a slot:
checkbox is not checked. What am I missing?
Upvotes: 8
Views: 5937
Reputation: 3738
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.
{ DB: 'prod-db', FOO: 'bar' }
{ DB: 'stg-db', BAZ: 'qux' }
[ 'DB', 'BAZ' ]
DB
sticky in prod
and stg
slots, BAZ
sticky in stg
slotparam 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' ]
}
}
}
Upvotes: 10
Reputation: 29766
You need to create a slotConfigNames resource:
Names for connection strings, application settings, and external Azure storage account configuration identifiers to be marked as sticky to the deployment slot and not moved during a swap operation. This is valid for all deployment slots in an app.
Something like that should work:
param functionAppName string
resource functionApp 'Microsoft.Web/sites@2018-11-01' existing = {
name: functionAppName
}
resource functionApps 'Microsoft.Web/sites/config@2021-03-01' = {
name: 'slotConfigNames'
parent: functionApp
properties: {
// Sticky app settings
appSettingNames: [
'AzureFunctionsJobHost__extensions__durableTask__hubName'
]
}
}
Upvotes: 7