ARM template deployment of Microsoft.Web/sites/hostNameBindings resources using copy

落花浮王杯 提交于 2020-07-08 13:00:09

问题


I use a copy operation over an array of Azure data center locations in order to deploy an app service plan and a website per location. I am able to create a traffic manager profile and use the copy object to add an endpoint per location to the traffic manager profile.

When I try to set the CNAME for each of the web sites to my custom domain name, using the Microsoft.Web/sites/hostNameBindings resource per the instructions here I came up with the following:

   {
      "type": "Microsoft.Web/sites/hostNameBindings",
      "apiVersion": "[parameters('hostNameBindingsApiVersion')]",
      "copy": {
        "name": "hostNameBindingsEndpointsLoop",
        "count": "[length(parameters('appServicePlanLocations'))]"
      },
      "name": "[concat(concat(variables('webSitePrefix'), parameters('appServicePlanLocations')[copyIndex()]), '/', variables('hostNameBindingsName'))]",
      "location": "[parameters('appServicePlanLocations')[copyIndex()]]",
      "dependsOn": [
        "[concat('Microsoft.Network/trafficManagerProfiles/', variables('trafficManagerName'), '/azureEndpoints/', variables('trafficManagerEndpointPrefix'), parameters('appServicePlanLocations')[copyIndex()])]",
        "[concat('Microsoft.Web/sites/', concat(variables('webSitePrefix'), parameters('appServicePlanLocations')[copyIndex()]))]"
      ],
      "properties": {
        "siteName": "[concat(variables('webSitePrefix'), parameters('appServicePlanLocations')[copyIndex()])]",
        "domainId": null,
        "hostNameType": "Verified"
      }
    }

Using this, the CNAME is actually set but the ARM template deployment fails with the following error:

{
      "ErrorEntity": {
        "Code": "Conflict",
        "Message": "Cannot modify this site because another operation is in progress. Details: Id: {guid}, OperationName: RegisterTrafficManagerProfile, CreatedTime: 5/24/2016 11:13:54 PM, RequestId: {guid}, EntityType: 1",
        "ExtendedCode": "59203",
        "MessageTemplate": "Cannot modify this site because another operation is in progress. Details: {0}",
        "Parameters": [
          "Id: {guid}, OperationName: RegisterTrafficManagerProfile, CreatedTime: 5/24/2016 11:13:54 PM, RequestId:{guid}, EntityType: 1"
        ],
        "InnerErrors": null
      }
    }
  ],
  "Innererror": null
}

I'm not sure what the conflict is because I've added the dependson segment to attempt to wait for both the website to be created as well as the trafficmanagerendpoint to complete its provisioning. I'm going to try to change the order such that after the website is created, I'll add the CNAME and then have the traffic manager endpoint await the CNAME creation. I don't see why the order should make a difference.

Have I defined the Microsoft.Web/sites/hostNameBindings section of my arm template correctly? Does the dependson order matter in this scenario? Should it?


回答1:


As mentioned by others it seems Traffic Manager causes a problem with the asynchronous hostNameBindings iteration operation.

It can be resolved by specifying a synchronous copy using "mode": "serial" mode with "batchsize": 1:

{
   "type": "Microsoft.Web/sites/hostNameBindings",
   "apiVersion": "[parameters('hostNameBindingsApiVersion')]",
   "copy": {
     "name": "hostNameBindingsEndpointsLoop",
     "count": "[length(parameters('appServicePlanLocations'))]",

     /* FIX for Asynchronous Hostname Conflict */
     "mode": "serial",
     "batchSize": 1
  },
  …

Explanation of the "mode" and "batchSize" properties can be found here:

https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-multiple#resource-iteration




回答2:


When you add a Web App to Traffic Manager, there is some asynchronous coordination that happens behind the scenes between the two services, to check that the Web App SKU is eligible for Traffic Manager and to register the Traffic Manager DNS name in the Web App custom domain names list.

It appears that this async process is causing the error you're seeing. Your suggestion of reversing the order, so your CNAME is created before the Traffic Manager registration, should work (I'd be interested to hear if it does).

Jonathan Tuliani, Program Manager, Azure Networking - DNS and Traffic Manager



来源:https://stackoverflow.com/questions/37441886/arm-template-deployment-of-microsoft-web-sites-hostnamebindings-resources-using

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