4

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?

Paul
  • 1,590
  • 5
  • 20
  • 41
  • I ran into a similar issue once I had multiple hostnameBindings for the same site in the ARM template. What fixed it was ensuring that they are not deployed in parallel. After adding a dependency between the hostnameBindings to enforce sequential deployment that error was gone, – Torben Knerr Mar 29 '19 at 14:38

2 Answers2

7

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://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-multiple#resource-iteration

Simon Gregory
  • 566
  • 7
  • 10
  • Thanks for your code gist. Finally, I could get the multiple hostNameBindings set using copy. I have shared my implementation in a [blog post](https://davidsekar.com/arm/cannot-modify-this-site-because-another-operation-is-in-progress) . Hope it helps. – David Chelliah Mar 02 '20 at 18:25
1

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

  • Thanks for your response. I tried reversing the dependency order early this AM but started running into other, seemingly unrelated issues. I need to focus on a completely separate issue that has come up this afternoon, but will come back to this issue later this evening. – Paul May 26 '16 at 18:05
  • I'm still seeing errors (albeit different ones) after switching the dependency order. I'll update the post to include error details that occur when switching dependency order. – Paul Jun 03 '16 at 16:43
  • So apparently there were issues with the Azure Portal earlier today and the errors I just mentioned may have been a red herring. Retesting... – Paul Jun 03 '16 at 20:35
  • I tried reversing the dependency order, but ran into another issue... I was forced to add CNAMEs for each of the regional websites so that the hostNameBindings could verify them. I would rather not have to define the CNAMEs on a per region basis and really only wanted to have to define it at the traffic manager level. I was eventually able to figure out the issue with the order I originally attempted. – Paul Jun 03 '16 at 20:54
  • Well apparently I spoke too soon. While I was able to get the deployment to work successfully, I can't delete and recreate the resource group successfully. I continue to get 'Cannot modify this site because another operation is in progress' errors. – Paul Jun 03 '16 at 22:04
  • Hi Paul, do you have more than one hostnameBindings for that site in your ARM template? If so, you may need to ensure they are deployed sequentially and not in parallel (see my comment above) – Torben Knerr Mar 29 '19 at 14:41