Reading Time: 3 minutes

Today morning I had to deploy some new rules on an existing production Azure Load Balancer. So, I spun up the VS Code and my JSON ARM Template library to make the appropriate changes. Little did I know that this would soon fail.

tldr: if you are just looking for the PowerShell script to do the job, skip my adventures and go here.

Setting the scene

It all started when I went to the Azure Portal and clicked on the load balancer in question and exported its template. The export was fine, no warning for missing properties or objects and so I opened it for adding my rules before redeploying it.

Export the ARM template of an Azure Resource from the Portal

I added the rule, after the last rule, and since no validation error was popping up, I set out to test the deployment:

Test-AzResourceGroupDeployment `
    -ResourceGroupName "resourcegroupname" `
    -TemplateFile "mytempate.json" `

To my disappointment I got the following reply from the Azure Resource Manager:

Circular dependency detected (click to enlarge)

I spend a couple of minutes back in the script and then I saw that the load balancer had “dependsOn” the “back-end pool” and at the bottom of the script the “back-end pool” had a “dependsOn” the load balancer. A clear case I suppose. What puzzled me at that moment was how can this happen as this script was exported from the Azure Portal and *logically* it should just work. Well, it seems that ARM templates exported from the portal need some manual labor before firing them back against the Azure Resource Manager.

And so I did. I commented out the first “dependsOn” as this made more sense to me, meaning you need a load balancer object and the you can create a back-end pool inside it. I executed the test deployment again:

Tada! 🙂

“Looking good”, I thought. So, I issued the deployment execution and got this:

Weird deployment error(?) (click to enlarge)

Now, the issue is that this seems to be an error, but, the change *was* applied successfully. Not so nice, Azure.

If one looks closer to the output it states “provisioning status is succeeded” and then you get the red text saying something about not being able to do “something?” on the back-end pool because the load balancer is not “Standard SKU”. That is, to put it mildly… bad. I didn’t try to change something on the back-end pool, just added a rule, Azure.

Starting your day with inconsistencies is no good. So, until I get to the bottom of this, probably on another blog post, I turned to my friend the PowerShell.

Adding the rules through the Azure Portal could have been an option, but it is no joy to wait for each rule ~1 minute and then refresh the page because the state in the rules remains to “Updating” and the “+Add” button is disabled. So, wasting ~1,5 minutes + the frustration per rule, for something that I will need to also in the future was a no brainer to turn to a script.

not in this case but totally true 🙂

Below the script that made my day looking better.

Hope it helps.