SQL Server with Mr. Denny

Jun 18 2018   7:29PM GMT

JSON documents in Azure and IF/THEN blocks

Denny Cherry Denny Cherry Profile: Denny Cherry

Tags:
Azure
JSON

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

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: