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

时间:2016-03-24 09:20:54

标签: azure azure-powershell azure-resource-manager arm-template

我创建了一个用于部署Azure Service Bus的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]"
        }
    }
}

有人也有同样的问题,或者我错过了一些愚蠢的事情?有修复吗?

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:8)

MS帮助我解决了这个问题。问题是授权规则是并行创建的,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]"
        }
    }
}