Create Azure web app slot from ARM template without copying original web app configuration

冷暖自知 提交于 2019-12-21 23:09:05

问题


I am trying to create web app slots through ARM template.

I was able to create those but it looks like the default behavior is to create the them as a copy of the current web app state. This result in my slot inheriting app settings, connection strings, virtual directories, ....

Here a reproduction sample which demonstrate the behavior https://github.com/ggirard07/ARMSlotWebConfig.

I want my slot clean and fresh instead, which is the azure portal default behavior. The portal is able to allow a user to select the behavior by specifying the "configSource": "", value it posts when creating the slot.

Is there anyway to achieve the same from inside an ARM template?


回答1:


To prevent the copying of settings from the production app, just add an empty siteConfig object in the slot properties. e.g.

    {
      "apiVersion": "2015-08-01",
      "type": "slots",
      "name": "maintenance",
      "location": "[resourceGroup().location]",
      "dependsOn": [
        "[resourceId('Microsoft.Web/Sites/', variables('webSiteName'))]"
      ],
      "properties": {
        "siteConfig": { }
      }
    }

I sent a PR to illustrate on your repo.




回答2:


Is there anyway to achieve the same from inside an ARM template?

If I use the template you mentioned, I also can reproduce it on my side. I also can't find a way to select the behavior by specifying the "configSource": "" directly, You could give feedback to Azure team.

I work it out with overriding the config during deploy slot. It works correctly on my side. You could use the following code to replace the creating WebApp slot code in your tempalte.

    {
      "apiVersion": "2015-08-01",
      "name": "maintenance",
      "type": "slots",
      "location": "[resourceGroup().location]",
      "dependsOn": [
        "[resourceId('Microsoft.Web/Sites', variables('webSiteName'))]"
      ],
      "properties": {
      },
      "resources": [
        {
          "apiVersion": "2015-08-01",
          "type": "config",
          "name": "connectionstrings",
          "location": "East US",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites/Slots', variables('webSiteName'), 'maintenance')]"
          ],
          "properties": {}
        },
        {
          "apiVersion": "2015-08-01",
          "type": "config",
          "name": "web",
          "tags": {
            "displayName": "Website configuration"
          },
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites/Slots', variables('webSiteName'),'maintenance')]"
          ],
          "properties": {
            "virtualApplications": [
              {
                "virtualPath": "/",
                "physicalPath": "site\\wwwroot",
                "preloadEnabled": true,
                "virtualDirectories": null
              }
            ]
          }
        }

      ]

    }


来源:https://stackoverflow.com/questions/50024342/create-azure-web-app-slot-from-arm-template-without-copying-original-web-app-con

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!