title: Why does my ARM template, fail to create authorization rules consistently?
body: <p>I have created an ARM template for deploying Azure Service Bus which also includes event hub and queues. The template creates the queues and event hubs successfully but some times the authorization rules some how is not created (20% of the time). Below is the trimmed version of the template which I have created after a struggle :P.</p>
  
  <pre><code>{
      "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {
          "location": {
              "type": "string",
              "defaultValue": "South Central US",
              "metadata": {
                  "description": "The location where all azure resources will be deployed."
              }
          },
          "serviceBusNamespace": {
              "type": "string",
              "minLength": 1,
              "metadata": {
                  "description": "The name of the service bus namespace to create."
              }
          },
          "queueName": {
              "type": "string",
              "minLength": 1,
              "metadata": {
                  "description": "The name of the queue to create."
              }
          },
          "hubName": {
              "type": "string",
              "minLength": 1,
              "metadata": {
                  "description": "The name of the event hub to create."
              }
          },
          "messagingSku": {
              "type": "int",
              "minValue": 1,
              "defaultValue": 1,
              "metadata": {
                  "description": "The SKU version."
              }
          },
          "queueMaxSizeInGB": {
              "type": "int",
              "minValue": 1,
              "defaultValue": 1,
              "maxValue": 16,
              "metadata": {
                  "description": "The queue max size."
              }
          },
          "partitionCount": {
              "type": "int",
              "minValue": 2,
              "defaultValue": 2,
              "maxValue": 32,
              "metadata": {
                  "description": "The partition count of event hub."
              }
          }
      },
      "variables": {
          "queueSize": "[mul(parameters('queueMaxSizeInGB'),1024)]",
          "managePolicy": "ManagePolicy",
          "sendPolicy": "SendPolicy",
          "listenPolicy": "ListenPolicy"
      },
      "resources": [
          {
              "apiVersion": "2014-09-01",
              "name": "[parameters('serviceBusNamespace')]",
              "type": "Microsoft.ServiceBus/namespaces",
              "location": "[parameters('location')]",
              "properties": {
                  "messagingSku": "[parameters('messagingSku')]"
              },
              "resources": [
                  {
                      "apiVersion": "2014-09-01",
                      "name": "[parameters('queueName')]",
                      "type": "Queues",
                      "dependsOn": [
                          "[concat('Microsoft.ServiceBus/namespaces/', parameters('serviceBusNamespace'))]"
                      ],
                      "properties": {
                          "path": "[parameters('queueName')]",
                          "maxSizeInMegabytes": "[variables('queueSize')]"
                      },
                      "resources": [
                          {
                              "apiVersion": "2015-08-01",
                              "name": "[variables('managePolicy')]",
                              "type": "authorizationRules",
                              "dependsOn": [
                                  "[concat('Microsoft.ServiceBus/namespaces/', parameters('serviceBusNamespace'),'/queues/',parameters('queueName'))]"
                              ],
                              "properties": {
                                  "Rights": [
                                      "Send",
                                      "Listen",
                                      "Manage"
                                  ]
                              }
                          },
                          {
                              "apiVersion": "2015-08-01",
                              "name": "[variables('sendPolicy')]",
                              "type": "authorizationRules",
                              "dependsOn": [
                                  "[concat('Microsoft.ServiceBus/namespaces/', parameters('serviceBusNamespace'),'/queues/',parameters('queueName'))]"
                              ],
                              "properties": {
                                  "Rights": [
                                      "Send"
                                  ]
                              }
                          },
                          {
                              "apiVersion": "2015-08-01",
                              "name": "[variables('listenPolicy')]",
                              "type": "authorizationRules",
                              "dependsOn": [
                                  "[concat('Microsoft.ServiceBus/namespaces/', parameters('serviceBusNamespace'),'/queues/',parameters('queueName'))]"
                              ],
                              "properties": {
                                  "Rights": [
                                      "Listen"
                                  ]
                              }
                          }
                      ]
                  },
                  {
                      "apiVersion": "2014-09-01",
                      "name": "[parameters('hubName')]",
                      "type": "EventHubs",
                      "dependsOn": [
                          "[concat('Microsoft.ServiceBus/namespaces/', parameters('serviceBusNamespace'))]"
                      ],
                      "properties": {
                          "path": "[parameters('hubName')]",
                          "partitionCount": "[parameters('partitionCount')]"
                      }
                  }
              ]
          }
      ],
      "outputs": {
          "queueManagePolicy": {
              "type": "string",
              "value": "[listKeys(resourceId('Microsoft.ServiceBus/namespaces/queues/authorizationRules',parameters('serviceBusNamespace'),parameters('queueName'),variables('managePolicy')),'2015-08-01').primaryConnectionString]"
          },
          "queueSendPolicy": {
              "type": "string",
              "value": "[listKeys(resourceId('Microsoft.ServiceBus/namespaces/queues/authorizationRules',parameters('serviceBusNamespace'),parameters('queueName'),variables('sendPolicy')),'2015-08-01').primaryConnectionString]"
          },
          "queueListenPolicy": {
              "type": "string",
              "value": "[listKeys(resourceId('Microsoft.ServiceBus/namespaces/queues/authorizationRules',parameters('serviceBusNamespace'),parameters('queueName'),variables('listenPolicy')),'2015-08-01').primaryConnectionString]"
          }
      }
  }
  </code></pre>
  
  <p>Is somebody also having the same issue or I am missing something silly? Is there a fix?</p>
  
  <p>Any help is greatly appreciated.</p>