
close
close
Want to know about the security benefits of Microsoft's E5 license?
In this step-by-step post, I’m going to show you, without using the paid-for version of Visual Studio, how to build a simple JSON file using the Azure Portal, and customize it using the free version of Visual Studio, VS Code.
Before you proceed, you should read the following posts:
I have found that the easiest way to build a JSON that you can start with is to deploy something by hand in the Azure Portal. For this simple example, I’m going to deploy a resource group with a single storage account. Note that the boundary of a JSON deployment in Azure is the resource group:
My deployment is as follows:
The manually deployed resource group and storage account [Image Credit: Aidan Finn]
The default JSON of the manual deployment [Image Credit: Aidan Finn]
I have installed the free VS Code with the Azure Resource Manager Tools (a free plugin) on my Surface Book and use this to edit JSON files; the addition of the plugin provides some handy JSON-awareness.
Launch VS Code and paste the copied JSON template into a new window. Note that VS Code will see this as simple text until you save the file as a JSON file; VS Code will color code the text immediately after the save operation.
The default JSON in VS Code [Image Credit: Aidan Finn]
I am going to rename the “storageAccounts_sapetri_name” parameter to “Storage Account Name”. This means that all references to “storageAccounts_sapetri_name” must be updated to “Storage Account Name”. The default will be null; we cannot have people trying to reuse a default storage account name because storage account names must be globally unique.
I am also going to add a second parameter called Storage Account Resiliency. This parameter will allow the person deploying the template to choose between LRS (Standard_LRS) or GRS (Standard_GRS), with LRS as the default setting. I will end up with the following parameters section:
"parameters": { "Storage Account Name": { "defaultValue": null, "type": "string" }, "Storage Account Resiliency": { "type": "string", "defaultValue": "Standard_LRS", "allowedValues": [ "Standard_LRS", "Standard_GRS" ] } },
I want to ensure that my new storage account is deployed into a region that matches the region of the resource group. This can be done using a handy function, as depicted below. I will create a variable that stores the resource group location and can be used by all resources within this template.
"variables": { "RGLocation": "[resourceGroup().location]" },
We have just a single resource in this JSON file – a storage account. The first thing that I want to do is modify the comment, which, by default, lists the subscription, resource group, resource type, and name of the source resource. I want to change it to something that describes the purpose of the resource in the template.
I have defined a parameter called “Storage Account Resiliency” to allow an administrator select the resiliency of the new storage account. The resource has a hard-coded value in a setting called sku\name. I will change this to refer to the new parameter.
I’ve also created a variable to define the location of the resource group. I want all resources to use this location, instead of using some hard-coded location – this will allow me to deploy my JSON to any resource group to any Azure region. I will modify the location setting of the resource to use the variable “RGLocation”.
"resources": [ { "comments": "Will be used to store virtual machines in this resource group", "type": "Microsoft.Storage/storageAccounts", "sku": { "name": "[parameters('Storage Account Resiliency')]", "tier": "Standard" }, "kind": "Storage", "name": "[parameters('Storage Account Name')]", "apiVersion": "2016-01-01", "location": "[variables('RGLocation')]", "tags": {}, "properties": {}, "resources": [], "dependsOn": [] } ]
Make sure that you save the JSON file and look for any errors or warnings in the bottom-left of VS Code.
When you deploy the finished template, you are asked for two pieces of information:
Deploying the new JSON template [Image Credit: Aidan Finn]
{ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "Storage Account Name": { "defaultValue": null, "type": "string" }, "Storage Account Resiliency": { "type": "string", "defaultValue": "Standard_LRS", "allowedValues": [ "Standard_LRS", "Standard_GRS" ] } }, "variables": { "RGLocation": "[resourceGroup().location]" }, "resources": [ { "comments": "Will be used to store virtual machines in this resource group", "type": "Microsoft.Storage/storageAccounts", "sku": { "name": "[parameters('Storage Account Resiliency')]", "tier": "Standard" }, "kind": "Storage", "name": "[parameters('Storage Account Name')]", "apiVersion": "2016-01-01", "location": "[variables('RGLocation')]", "tags": {}, "properties": {}, "resources": [], "dependsOn": [] } ] }
This is a very simple example of a JSON. In a soon-to-be-published post, I’ll expand on this JSON by adding more resources.
More in Cloud Computing
Google to Open Three New Cloud Regions in Malaysia, Thailand, and New Zealand
Aug 10, 2022 | Rabia Noureen
Oracle Teams Up with Microsoft to Launch New Database Service for Azure
Jul 21, 2022 | Rabia Noureen
Most popular on petri