JSON documents in Azure and IF/THEN blocks

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 Cloudflare being the cloudobjects, 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

The post JSON documents in Azure and IF/THEN blocks appeared first on SQL Server with Mr. Denny.

Share

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Trust DCAC with your data

Your data systems may be treading water today, but are they prepared for the next phase of your business growth?