为什么我的 ARM 模板无法始终如一地创建授权规则?

Why does my ARM template, fail to create authorization rules consistently?

我创建了一个用于部署 Azure 服务总线的 ARM 模板,其中还包括事件中心和队列。该模板成功创建了队列和事件中心,但有时授权规则未创建(20% 的时间)。下面是我经过努力创建的模板的修剪版本 :P.

{
    "$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]"
        }
    }
}

是否有人也有同样的问题,或者我遗漏了一些愚蠢的东西?有修复吗?

非常感谢任何帮助。

微软帮我解决了这个问题。问题是授权规则是并行创建的,这是 RM 不喜欢的。修复它的方法是简单地一个一个地创建 SAS 令牌。以下是始终有效的 ARM 模板

{
    "$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'))]",
                                "[concat('Microsoft.ServiceBus/namespaces/', parameters('serviceBusNamespace'),'/queues/',parameters('queueName'), '/authorizationRules/', variables('managePolicy'))]",
                            ],
                            "properties": {
                                "Rights": [
                                    "Send"
                                ]
                            }
                        },
                        {
                            "apiVersion": "2015-08-01",
                            "name": "[variables('listenPolicy')]",
                            "type": "authorizationRules",
                            "dependsOn": [
                                "[concat('Microsoft.ServiceBus/namespaces/', parameters('serviceBusNamespace'),'/queues/',parameters('queueName'))]",
                                "[concat('Microsoft.ServiceBus/namespaces/', parameters('serviceBusNamespace'),'/queues/',parameters('queueName'), '/authorizationRules/', variables('managePolicy'))]",
                                "[concat('Microsoft.ServiceBus/namespaces/', parameters('serviceBusNamespace'),'/queues/',parameters('queueName'), '/authorizationRules/', variables('sendPolicy'))]"
                            ],
                            "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]"
        }
    }
}