10

How can you deploy sticky settings to a production app slot in azure web apps using ARM templates without overwriting the existing app settings?

I'm using Azure ARM templates to deploy my environment and code releases. The environment has both Staging and Production slots. Part of the deployment is deploying AppSettings. We deploy to Staging, test, then swap to prod.

This system has been working well until now, when I need to deploy a sticky AppSetting to prod. Normally, the deployments are incremental, but when I try to create a sticky setting for production, all of the other settings get wiped out.

I'm using slotconfignames to specify the sticky variables in the prod slot

{
      "apiVersion": "2015-08-01",
      "name": "slotconfignames",
      "type": "config",
      "dependsOn": [
        "[resourceId('Microsoft.Web/Sites', variables('webSiteName'))]"
      ],
      "properties": {
        "appSettingNames": [ "WEBSITE_LOCAL_CACHE_OPTION", "WEBSITE_LOCAL_CACHE_SIZEINMB" ]
      }
    }

I've tried creating separate resources for the prod appsettings and the stage appsettings - when I do, the prod slot appsettings are completely overwritten. This is somewhat expected:

 {
      "apiVersion": "2015-08-01",
      "type": "config",
      "name": "appsettings",
      "dependsOn": [
        "[resourceId('Microsoft.Web/sites/', variables('webSiteName'))]"
      ],

      "properties": {
        "WEBSITE_LOCAL_CACHE_OPTION": "Always",
        "WEBSITE_LOCAL_CACHE_SIZEINMB": "2000"
      }
    },

If I make those same settings as part of the stage slot settings, then they aren't set on prod, but are set as sticky on the stage slot.

{
    "name": "appsettings",
    "type": "config",
    "apiVersion": "2015-08-01",
    "dependsOn": [
      "[variables('stagingSlotName')]",
      //"[concat('Microsoft.Web/sites/', variables('webSiteName'))]",
      "MSDeploy",
      "[concat('Microsoft.Resources/deployments/', 'AppStorage')]"
    ],
    "tags": {
      "displayName": "uisettings",
      "environment": "[parameters('environmentName')]",
      "serviceGroup": "[variables('serviceGroupName')]"
    },
    "properties": {
      ...othersettingshere...         
      "WEBSITE_LOCAL_CACHE_OPTION": "Always",
      "WEBSITE_LOCAL_CACHE_SIZEINMB": "2000"
    }
  },
Tom Sun - MSFT
  • 24,161
  • 3
  • 30
  • 47
shinybluesphere
  • 355
  • 3
  • 11

1 Answers1

2

when I need to deploy a sticky AppSetting to prod. Normally, the deployments are incremental, but when I try to create a sticky setting for production, all of the other settings get wiped out.

Based on my test, as you said, the App settings that are not defined in your ARM template will be wiped out. Please make sure you include all App settings in your ARM template when you specify sticky slot settings.

{
  "name": "appsettings",
  "type": "config",
  "apiVersion": "2015-08-01",
  "dependsOn": [
    "[concat('Microsoft.Web/sites/', variables('webSiteName'))]"
  ],
  "tags": {
    "displayName": "uisettings"
  },
  "properties": {
    "AppSettingKey1": "myvalue",
    //your other appsettings
    "WEBSITE_LOCAL_CACHE_OPTION": "Always",
    "WEBSITE_LOCAL_CACHE_SIZEINMB": "2000"
  }
},
{
  "apiVersion": "2015-08-01",
  "name": "slotconfignames",
  "type": "config",
  "dependsOn": [
    "[concat('Microsoft.Web/sites/', variables('webSiteName'))]"
  ],
  "properties": {
    "appSettingNames": [ "WEBSITE_LOCAL_CACHE_OPTION", "WEBSITE_LOCAL_CACHE_SIZEINMB" ]
  }
}
Fei Han
  • 26,415
  • 1
  • 30
  • 41
  • By this "the App settings that are not defined in your ARM template will be wiped out", you mean that you need to define all appsettings in both slots (both source and target slot), right? You cant just add the sticky setting, and then redeploy the ARM, then only the sticky setting will get rewritten, but all other settings will get wiped, correct? – mslot Mar 15 '20 at 14:48
  • 1
    But by having all the AppSettings here, doesn't this mean that you now deploy updated appsettings to the production slot at the point of running this ARM, rather than during the swap when you would want it to? – oatsoda Apr 07 '21 at 15:14
  • And doesn't deploying the settings on the Production slot cause restart of it? – oatsoda Apr 07 '21 at 15:17
  • 1
    The "slotconfignames" trick worked for me, thou I had to use "apiVersion": "2020-06-01". Thanks for the solution. – Sunil Johnson Apr 11 '23 at 15:59