Stick setting to staging slot

741 Views Asked by At

I have the following bicep file that adds deployment slots with config settings:

var appSettings = [
  {
    name: 'WEBSITE_RUN_FROM_PACKAGE'
    value: 1    
  }
  {
    name: 'WEBSITE_ENABLE_SYNC_UPDATE_SITE'
    value: 1    
  }
]

var stagingSettings = [ 
  {
    name: 'AzureWebJobs.StarterFunction.Disabled'
    value: 1
  }
]

var productionSettings = [ 
  {
    name: 'AzureWebJobs.StarterFunction.Disabled'
    value: 0
  }
]

module functionAppTemplate 'functionApp.bicep' = {
  name: 'functionAppTemplate'
  params: {
    name: '${functionAppName}'
    kind: functionAppKind
    location: location
    servicePlanName: servicePlanName
    secretSettings: union(appSettings, productionSettings)
  }
  dependsOn: [
    servicePlanTemplate
  ]
}

module functionAppSlotTemplate 'functionAppSlot.bicep' = {
  name: 'functionAppSlotTemplate'
  params: {
    name: '${functionAppName}/staging'
    kind: functionAppKind
    location: location
    servicePlanName: servicePlanName
    secretSettings: union(appSettings, stagingSettings)
  }
  dependsOn: [
    functionAppTemplate
  ]
}

functionApp.bicep:

resource functionApp 'Microsoft.Web/sites@2018-02-01' = {
  name: name
  location: location
  kind: kind
  properties: {
    serverFarmId: resourceId('Microsoft.Web/serverfarms', servicePlanName)
    clientAffinityEnabled: false
    httpsOnly: true
    siteConfig: {
      use32BitWorkerProcess : false
      appSettings: secretSettings
    }
  }
  identity: {
    type: 'SystemAssigned'
  }
}


resource functionAppSlotConfig 'Microsoft.Web/sites/config@2021-03-01' = {
  name: 'slotConfigNames'
  parent: functionApp
  properties: {
    appSettingNames: [
      'AzureWebJobs.StarterFunction.Disabled'
    ]
  }
}

functionAppSlot.bicep

resource functionAppSlot '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: secretSettings
    }
  }
  identity: {
    type: 'SystemAssigned'
  }
}

I want this setting 'AzureWebJobs.StarterFunction.Disabled' only for staging slot (NOT for production slot) and stick that setting to staging slot. How would I update this code?

2

There are 2 best solutions below

7
On

For each of your application settings you can add

"slotSetting": true

This will only enable it for the slot in question

0
On

It is not possible to stick a setting to a staging slot using bicep. You will need to stick the setting to your production slot.

You will need to use 'Microsoft.Web/sites/config@2022-03-01'

resource appServiceStickySetting 'Microsoft.Web/sites/config@2022-03-01' = {
  name: 'slotConfigNames'
  parent: appService // <-- This needs to be a /sites resource (reference error below)
  properties: {
    appSettingNames: [
      "Setting Name Here"
    ]
  }
}

Error You Get If You Enter For A Slot Setting