We will start with a pretty simple JSON that deploys a storage account into a resource group. The template asks, using parameters, the administrator to name the storage account and select a resiliency level for the Standard Storage (HDD) account. A variable (RGLocation) retrieves the Azure region of the desired resource group and is used to automatically place the new storage account into the same Azure region.
{
"$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": []
}
]
}
I want to add some resources to this JSON:
I could learn how to build out the syntax of these resources, but the snippets functionality of VS Code allows me to quickly add arm-vn (VNet) and arm-avail (availability set) resources to the template.
I added a comma to the brace that marks the end of the storage account resource, and then the following code is automatically added when I added an arm-vn snippet:
![The default new virtual network snippet [Image Credit: Aidan Finn]](https://petri.com/wp-content/uploads/petri-imported-images/JSONDefaultVNet.png)
I am also going to convert the following settings into parameters with default values:
I will have the following new parameters to customize the new network at the time of deployment:
![The new JSON parameters for the virtual network [Image Credit: Aidan Finn]](https://petri.com/wp-content/uploads/petri-imported-images/JSONCustomizedVNetParameters.png)
![The customized VNet in the Azure JSON [Image Credit: Aidan Finn]](https://petri.com/wp-content/uploads/petri-imported-images/JSONCustomizedVNet.png)
I added a comma after the brace that ends the VNet definition and then typed arm-availability to add an availability set, as shown below.
![The default Azure availability set JSON snippet [Image Credit: Aidan Finn]](https://petri.com/wp-content/uploads/petri-imported-images/JSONDefaultAvailabilitySet.png)
I will add a single parameter to the JSON file for the availability set:
![The added variable for the ARM availability set JSON definition [Image Credit: Aidan Finn]](https://petri.com/wp-content/uploads/petri-imported-images/JSONCustomizedAvailabilitySetParameters.png)
![The customized availability set in the Azure JSON [Image Credit: Aidan Finn]](https://petri.com/wp-content/uploads/petri-imported-images/JSONCustomizedAvailabilitySet.png)
Copying snippets from a website is a nightmare, so here is the complete JSON file:
{
"$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"
]
},
"Network Name": {
"defaultValue": "nw-petri",
"type": "string"
},
"Network Address": {
"defaultValue": "10.0.0.0/16",
"type": "string"
},
"Subnet-1 Name": {
"defaultValue": "sn-petri-01",
"type": "string"
},
"Subnet-1 Address": {
"defaultValue": "10.0.0.0/24",
"type": "string"
},
"Subnet-2 Name": {
"defaultValue": "sn-petri-02",
"type": "string"
},
"Subnet-2 Address": {
"defaultValue": "10.0.1.0/24",
"type": "string"
},
"Availability Set Name": {
"defaultValue": "as-petri-01",
"type": "string"
}
},
"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": []
},
{
"apiVersion": "2015-06-15",
"type": "Microsoft.Network/virtualNetworks",
"name": "[parameters('Network Name')]",
"location": "[variables('RGLocation')]",
"tags": {
"displayName": "[parameters('Network Name')]"
},
"properties": {
"addressSpace": {
"addressPrefixes": [
"[parameters('Network Address')]"
]
},
"subnets": [
{
"name": "[parameters('Subnet-1 Name')]",
"properties": {
"addressPrefix": "[parameters('Subnet-1 Address')]",
}
},
{
"name": "[parameters('Subnet-2 Name')]",
"properties": {
"addressPrefix": "[parameters('Subnet-2 Address')]",
}
}
]
}
},
{
"type": "Microsoft.Compute/availabilitySets",
"name": "[parameters('Availability Set Name')]",
"apiVersion": "2015-06-15",
"location": "[variables('RGLocation')]",
"tags": {
"displayName": "[parameters('Availability Set Name')]"
},
"properties": {}
}
]
}
You can deploy this template in several ways to quickly deploy a storage account, a virtual network (with two subnets), and an availability set with a minimal amount of effort, and you’ll get a consistent result every time.