Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 205
Paul Avatar asked Feb 06 '23 22:02

Paul


1 Answers

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

like image 61
Simon Gregory Avatar answered May 09 '23 13:05

Simon Gregory