If you do any work in Azure you’ve probably done deployments using JSON scripts. Originally JSON in Azure didn’t support much, you could create 20141009_104831objects, but if you put it in the JSON script, it would be created.

Thank thankfully isn’t the case anymore. We now have conditions in JSON in Azure which when used correctly can be very powerful. I’ve only had a couple of opportunities to use this new functionality, but it’s incredibly powerful. It’s all done by adding in a single line of code for the object in question. This syntax puts the following within the object.

“condition”: “[equals(parameters(‘newDeployment’), ‘true’)]”,

As long as the condition evaluates to true, then the object with this in the code will be created. Let’s look at an example to see how this can be used.

“resources”: [
{
“condition”: “[equals(parameters(‘newDeployment’), ‘true’)]”,
“type”: “Microsoft.Compute/availabilitySets”,
“name”: “[parameters(‘availabilitySets_DCs_name’)]”,
“apiVersion”: “2015-06-15”,
“location”: “[parameters(‘Location’)]”,
“properties”: {
“platformUpdateDomainCount”: 2,
“platformFaultDomainCount”: 2
},
“dependsOn”: []
},

As we can see in the sample code, as long as the value of the parameter “newDeployment” is “true” then this availability set in Azure will be created. This variable is set to $true or $false in PowerShell before it’s passed into the JSON, so normal handling can happen in PowerShell beforehand.

Hopefully, others will find this as useful as I did when creating JSON deployment scripts in Azure.

Denny 

About the Author

Denny Cherry

I am a Senior SQL Server DBA at CDW with 10 years of IT experience, mostly as a software developer building web and windows based applications (VB, VB.NET, C#, C++ and a smidge of Java). I have always found database design and set based logic interesting, so 3 years ago I took the plunge and became a DBA, soon after I discovered people would tell anyone who would listen all about the SQL Server internals. I was hooked. I have not looked back since. The things I say represent my opinion and in no way represent the views or opinions of my employer or coworkers.

Start the discussion at forums.toadworld.com