Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

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

Is somebody also having the same issue or I am missing something silly? Is there a fix?

Any help is greatly appreciated.

like image 554
Sandesh Avatar asked Jan 07 '23 09:01

Sandesh


1 Answers

MS helped me resolve the issue. The problem was that the authorization rules were getting created in parallel which RM does not like. The way to fix it is to simply create the SAS tokens one by one. Below is the consistently working ARM template

{
    "$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]"
        }
    }
}
like image 94
Sandesh Avatar answered May 09 '23 15:05

Sandesh