Deployment slot specific appsettin in ARM template?
U

5

12

I'm trying to get into that Visual Studio Resource Group template. So far it's looking good, and I have added some appsettings for a web app, but my question is, how can I make them deployment slot specific? Is there something in the json for the template or the parameter file?

Utopianism answered 30/10, 2016 at 19:50 Comment(1)
This can be found in resources.azure.com using already configured resources.Misesteem
C
12

Please have a try to add the json code snipped in the ARM template. I have tested it. It works successfully.

 "resources": [
        {
          "apiVersion": "2015-08-01",
          "name": "appsettings",
          "type": "config",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites/Slots', variables('webSiteName'), 'Staging')]"
          ],
          "properties": {
            "AppSettingKey1": "Some staging value",
            "AppSettingKey2": "My second staging setting",
            "AppSettingKey3": "My third staging setting"
          }
        }
      ]

The following are my detail steps:

1. Create a new Azure Resource group project (More detail please refer to document)

enter image description here

2. The Demo just for the Azure Website Slot App setting configuration, so remove the other resource from the project.

enter image description here

3. Add the Slot configuration into the deployment file enter image description here

4. Publish the Deployment  

enter image description here

The full json code :

  {
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "hostingPlanName": {
      "type": "string",
      "minLength": 1
    },
    "skuName": {
      "type": "string",
      "defaultValue": "S1",
      "allowedValues": [
        "F1",
        "D1",
        "B1",
        "B2",
        "B3",
        "S1",
        "S2",
        "S3",
        "P1",
        "P2",
        "P3",
        "P4"
      ],
      "metadata": {
        "description": "Describes plan's pricing tier and instance size. Check details at https://azure.microsoft.com/en-us/pricing/details/app-service/"
      }
    },
    "skuCapacity": {
      "type": "int",
      "defaultValue": 1,
      "minValue": 1,
      "metadata": {
        "description": "Describes plan's instance count"
      }
    }
  },
  "variables": {
    "webSiteName": "[concat('webSite', uniqueString(resourceGroup().id))]"
  },
  "resources": [
    {
      "apiVersion": "2015-08-01",
      "name": "[parameters('hostingPlanName')]",
      "type": "Microsoft.Web/serverfarms",
      "location": "[resourceGroup().location]",
      "tags": {
        "displayName": "HostingPlan"
      },
      "sku": {
        "name": "[parameters('skuName')]",
        "capacity": "[parameters('skuCapacity')]"
      },
      "properties": {
        "name": "[parameters('hostingPlanName')]"
      }
    },
    {
      "apiVersion": "2015-08-01",
      "dependsOn": [
        "[concat('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]"
      ],
      "location": "[resourceGroup().location]",
      "name": "[variables('webSiteName')]",
      "properties": {
        "name": "[variables('webSiteName')]",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]"
      },
      "resources": [
        {
          "apiVersion": "2015-08-01",
          "name": "Staging",
          "type": "slots",
          "location": "[resourceGroup().location]",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', variables('webSiteName'))]"
          ],
          "properties": {
          },
          "resources": [
            {
              "apiVersion": "2015-08-01",
              "name": "appsettings",
              "type": "config",
              "dependsOn": [
                "[resourceId('Microsoft.Web/Sites/Slots', variables('webSiteName'), 'Staging')]"
              ],
              "properties": {
                "AppSettingKey1": "Some staging value",
                "AppSettingKey2": "My second staging setting",
                "AppSettingKey3": "My third staging setting"
              }
            }
          ]
        }

      ],
      "tags": {
        "[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]": "Resource",
        "displayName": "Website"
      },
      "type": "Microsoft.Web/sites"
    }
  ]
}

We also can get the slot type from the azure resource ,if you have any slots on the Azure portal. enter image description here I also find a similar thread in the SO.

Cay answered 31/10, 2016 at 13:7 Comment(5)
Thanks a lot! Didn't know there was a slots type. Is there a documentation of the schema somewhere?Utopianism
I have updated the answer and added a snopshot of azure resource for it.Cay
@Tom Sun. Really useful template example there for SLOTS. Thanks for posting.Hanway
@Utopianism ARM reference: learn.microsoft.com/en-us/azure/templates/microsoft.web/…Faefaeces
This is not correct answer; it just wipes out all settings inherited from main site and sets new properties. Moreover, none of the properties are marked to be "slot specific". Answer by @joe-newton is correct. Volker, you want to select it as correct answer to the question.Paris
M
17

The accepted answer is correct, but leaves out an important piece of information. Under its current implementation, when swapping slots the AppSettings configuration for the slot will be swapped along with the deployment. If you are concerned about slot-specific configuration then this probably is not desirable for you.

To make the configuration "Sticky" to a slot, use the following resource in your ARM template. Note that the slotconfignames section has been added to the ARM template snippet from Tom's answer above.

"resources": [
        {
          "apiVersion": "2015-08-01",
          "name": "appsettings",
          "type": "config",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites/Slots', variables('webSiteName'), 'Staging')]"
          ],
          "properties": {
            "AppSettingKey1": "Some staging value",
            "AppSettingKey2": "My second staging setting",
            "AppSettingKey3": "My third staging setting"
          },
      {
        "apiVersion": "2015-08-01",
        "name": "slotconfignames",
        "type": "config",
        "dependsOn": [
          "[resourceId('Microsoft.Web/Sites', variables('webSiteName'))]"
        ],
        "properties": {
          "appSettingNames": [ "AppSettingKey1", "AppSettingKey2" ]
        }
      }
    ]

This will make AppSettingKey1 and AppSettingKey2 sticky to the Staging slot (They will not swap along with the deployment).

See "Azure Resource Manager Templates Tips and Tricks" from Anthony Chu for more details on sticky slot settings as well as other ARM template tips.

Mccay answered 5/6, 2017 at 14:22 Comment(7)
Where we can set the value for these slot settings (AppSettingKey1 and AppSettingKey2)?Clinical
You can add the values for these settings in the appsettings -> properties section as shown in my example above. "AppSettingKey1": "Some staging value" is actually setting the value for the slot.Mccay
Have you tested it? slotConfigNames does not exist on slots but only on the main web appTranscendentalism
@Transcendentalism Yes, I have tested it. The top level resources collection is a property of the website object itself, not the slot.Mccay
Where is the documentation for this "slotConfigNames", I see everyone talk about it but its like someone pulled it out of thin air.Dis
@AnthonyKlotz i couldn't find any documentation on this but it works. I needed to lock certain app settings to my production slot. Defining the "slotconfignames" resource and listing the desired "sticky" settings worked perfectly.Lockjaw
I like this answer. However, can someone explain to me where in the template is the setting for the main slot set? Here it seems we are just setting values for AppSettingKey1 and AppSettingKey2 in staging slot. What are the corresponding values for these in the primary slot? Is that not done in the template?Briefless
C
12

Please have a try to add the json code snipped in the ARM template. I have tested it. It works successfully.

 "resources": [
        {
          "apiVersion": "2015-08-01",
          "name": "appsettings",
          "type": "config",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites/Slots', variables('webSiteName'), 'Staging')]"
          ],
          "properties": {
            "AppSettingKey1": "Some staging value",
            "AppSettingKey2": "My second staging setting",
            "AppSettingKey3": "My third staging setting"
          }
        }
      ]

The following are my detail steps:

1. Create a new Azure Resource group project (More detail please refer to document)

enter image description here

2. The Demo just for the Azure Website Slot App setting configuration, so remove the other resource from the project.

enter image description here

3. Add the Slot configuration into the deployment file enter image description here

4. Publish the Deployment  

enter image description here

The full json code :

  {
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "hostingPlanName": {
      "type": "string",
      "minLength": 1
    },
    "skuName": {
      "type": "string",
      "defaultValue": "S1",
      "allowedValues": [
        "F1",
        "D1",
        "B1",
        "B2",
        "B3",
        "S1",
        "S2",
        "S3",
        "P1",
        "P2",
        "P3",
        "P4"
      ],
      "metadata": {
        "description": "Describes plan's pricing tier and instance size. Check details at https://azure.microsoft.com/en-us/pricing/details/app-service/"
      }
    },
    "skuCapacity": {
      "type": "int",
      "defaultValue": 1,
      "minValue": 1,
      "metadata": {
        "description": "Describes plan's instance count"
      }
    }
  },
  "variables": {
    "webSiteName": "[concat('webSite', uniqueString(resourceGroup().id))]"
  },
  "resources": [
    {
      "apiVersion": "2015-08-01",
      "name": "[parameters('hostingPlanName')]",
      "type": "Microsoft.Web/serverfarms",
      "location": "[resourceGroup().location]",
      "tags": {
        "displayName": "HostingPlan"
      },
      "sku": {
        "name": "[parameters('skuName')]",
        "capacity": "[parameters('skuCapacity')]"
      },
      "properties": {
        "name": "[parameters('hostingPlanName')]"
      }
    },
    {
      "apiVersion": "2015-08-01",
      "dependsOn": [
        "[concat('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]"
      ],
      "location": "[resourceGroup().location]",
      "name": "[variables('webSiteName')]",
      "properties": {
        "name": "[variables('webSiteName')]",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]"
      },
      "resources": [
        {
          "apiVersion": "2015-08-01",
          "name": "Staging",
          "type": "slots",
          "location": "[resourceGroup().location]",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', variables('webSiteName'))]"
          ],
          "properties": {
          },
          "resources": [
            {
              "apiVersion": "2015-08-01",
              "name": "appsettings",
              "type": "config",
              "dependsOn": [
                "[resourceId('Microsoft.Web/Sites/Slots', variables('webSiteName'), 'Staging')]"
              ],
              "properties": {
                "AppSettingKey1": "Some staging value",
                "AppSettingKey2": "My second staging setting",
                "AppSettingKey3": "My third staging setting"
              }
            }
          ]
        }

      ],
      "tags": {
        "[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]": "Resource",
        "displayName": "Website"
      },
      "type": "Microsoft.Web/sites"
    }
  ]
}

We also can get the slot type from the azure resource ,if you have any slots on the Azure portal. enter image description here I also find a similar thread in the SO.

Cay answered 31/10, 2016 at 13:7 Comment(5)
Thanks a lot! Didn't know there was a slots type. Is there a documentation of the schema somewhere?Utopianism
I have updated the answer and added a snopshot of azure resource for it.Cay
@Tom Sun. Really useful template example there for SLOTS. Thanks for posting.Hanway
@Utopianism ARM reference: learn.microsoft.com/en-us/azure/templates/microsoft.web/…Faefaeces
This is not correct answer; it just wipes out all settings inherited from main site and sets new properties. Moreover, none of the properties are marked to be "slot specific". Answer by @joe-newton is correct. Volker, you want to select it as correct answer to the question.Paris
B
2

"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 slot. The actual value for the slot specific setting should still be specified on the slot settings.

"resources": [
{
  "apiVersion":"[variables('siteApiVersion')]",
  "name":"[variables('WebAppName')]",
  "type":"Microsoft.Web/sites",
  "kind":"api",
  "location":"[variables('location')]",      
  "tags":{
     "[concat('hidden-related:', resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName')))]":"empty"
  },
  "properties":{
     "name":"[variables('WebAppName')]",
     "serverFarmId":"[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
     "siteConfig":{
        "AlwaysOn":"[parameters('AppServiceAlwaysOn')]"
     }
  },
  "resources":[
     {
        "apiVersion":"[variables('apiVersion')]",
        "type":"config",
        "name":"appsettings",
        "dependsOn":[
           "[variables('WebAppName')]"
        ],
        "properties":{}
     },
      {
        "apiVersion":"[variables('siteApiVersion')]",
        "type": "config",                  
        "name": "slotconfignames",
        "dependsOn": [
          "[concat('Microsoft.Web/sites/', variables('WebAppName'))]"
        ],
        "properties": {
          "appSettingNames": [ "WEBJOBS_DISABLE_SCHEDULE" ]
        }
      },
      {
        "apiVersion":"[variables('siteApiVersion')]",
        "condition":"[parameters('stagingSlotEnabled')]",
        "name":"[parameters('stagingSlotName')]",
        "type":"slots",
        "tags":{
           "displayName":"[concat(variables('WebAppName'), ' ', parameters('stagingSlotName'))]"
        },
        "location":"[variables('location')]",
        "dependsOn":[
           "[resourceId('Microsoft.Web/Sites', variables('WebAppName'))]"
        ],
        "properties":{},
        "resources":[
          {
            "apiVersion":"[variables('apiVersion')]",
            "type":"config",                  
            "name":"appsettings",
            "dependsOn":[
              "[resourceId('Microsoft.Web/Sites/Slots', variables('WebAppName'), parameters('stagingSlotName'))]"
            ],
            "properties":{
              "WEBJOBS_DISABLE_SCHEDULE" : "1"
            }
          }
        ]
     }
  ]
}

]

Board answered 16/8, 2018 at 8:43 Comment(1)
"apiVersion":"[variables('apiVersion')]" Microsoft says NOT to do this. learn.microsoft.com/en-us/azure/azure-resource-manager/…Fulfill
O
1

After scratching head a thousand times i found the solution !

  1. for production slot (Default slot) you need to add the resource(sub resource of sites) as bellow

    "resources":[ { "name":"appsettings", "type":"config", "apiVersion":"2018-11-01", "dependsOn":[ "[concat('Microsoft.Web/sites/', parameters('webAppName'))]" ], "tags":{ "displayName":"uisettings" }, "properties":{ "AppSettingKey1":"myvalue", "WEBSITE_LOCAL_CACHE_OPTION":"Always", "WEBSITE_LOCAL_CACHE_SIZEINMB":"2000" } }, { "name":"connectionstrings", "type":"config", "location":"[parameters('location')]", "tags":{ "displayName":"uisettings" }, "apiVersion":"2018-11-01", "dependsOn":[ "[resourceId('Microsoft.Web/sites',parameters('webAppName'))]" ], "properties":{ "ConnString2":{ "value":"[parameters('connectionstring')]", "type":"SQLServer" } } }, { "apiVersion":"2018-11-01", "name":"slotconfignames", "type":"config", "dependsOn":[ "[concat('Microsoft.Web/sites/', parameters('webAppName'))]" ], "properties":{ "appSettingNames":[ "WEBSITE_LOCAL_CACHE_OPTION", "WEBSITE_LOCAL_CACHE_SIZEINMB" ], "connectionStringNames":[ "ConnString2" ] } } ]

  2. for slots you dont need the "slotconfignames" resource slotconfignames is only for the default(production slot) PFA the working code for slot

    "resources":[ { "name":"appsettings", "type":"config", "apiVersion":"2018-11-01", "dependsOn":[ "[resourceId('Microsoft.Web/sites/slots',parameters('webAppName'),'Staging')]" ], "tags":{ "displayName":"uisettings" }, "properties":{ "AppSettingKey1":"myvalue", "WEBSITE_LOCAL_CACHE_OPTION":"Always", "WEBSITE_LOCAL_CACHE_SIZEINMB":"2000" } }, { "name":"connectionstrings", "type":"config", "location":"[parameters('location')]", "tags":{ "displayName":"uisettings" }, "apiVersion":"2018-11-01", "dependsOn":[ "[resourceId('Microsoft.Web/sites/slots',parameters('webAppName'),'Staging')]" ], "properties":{ "ConnString2":{ "value":"[parameters('connectionstring')]", "type":"SQLServer" } } } ],

Ought answered 9/1, 2020 at 5:37 Comment(0)
R
1

Updated for 2023

@Joe Newtons 's answer is correct, but not up to date for newer API versions. This is his answer but formatted for api version 2022-09-01 and to have the app settings be sticky in your Production slot

Only the fields of interest are displayed

"resources": [
    {
        "type": "Microsoft.Web/sites",
        "apiVersion": "2022-09-01",
        "name": "variables('webSiteName')",
        "dependsOn": [
            "[resourceId('Microsoft.Web/serverfarms', variables('serverFarmsName'))]"
        ],
        "properties": {
            "siteConfig": {
                "appSettings": [
                    {
                        "name": "AppSettingKey1",
                        "value": "Value1"
                    },
                    {
                        "name": "AppSettingKey2",
                        "value": "Value2"
                    },
                    {
                        "name": "AppSettingKey3",
                        "value": "Value3"
                    }
                ],
            }
        },
    },
    {
        "type": "Microsoft.Web/sites/config",
        "apiVersion": "2022-09-01",
        "name": "[concat(variables('webSiteName'), '/slotconfignames')]",
        "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', variables('webSiteName'))]"
        ],
        "properties": {
            "appSettingNames": [ "AppSettingKey1", "AppSettingKey2" ]
        }
    },
]
Rameses answered 27/12, 2023 at 14:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.