visual-studio-2015azure-powershellazure-resource-managerazure-deployment-slotsazure-resource-group

Deployment slot specific appsettin in ARM template?


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?


Solution

  • 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.