ARM Template hands-on lab.

  1. Option to create ‘n’ number of VMs associated with dedicated storage accounts along and public IPs. All these VMs share one common storage account for diagnostics.
  2. All the VMs will have an additional data disk.
  3. Virtual network with one subnet.
  4. Create Azure SQL server instance along with database.
  5. All of these resources will reside inside a single resource group.
  6. Use VSTS CI/CD pipeline for deployment.

copy and copyIndex(): This function is used to iteratively deploy the resource. So if you would like to create any resource more than once use copyIndex() function, by defining the count. copy object have 3 properties name, count and mode. Mode you can either have parallel or sequential (depends on design). You also need to update the resource name by using copyIndex(). This will ensure that resource name have the number associated with it.

Define number of VM’s

"vmCount":{
"type": "int",
"defaultValue": 2,
"metadata": {
"value": "number of VM"
}
},

Create resources

{
"comments": "Create Public IP for VMs",
"apiVersion": "2016-03-30",
"type": "Microsoft.Network/publicIPAddresses",
"name": "[concat(variables('publicIPProperty').publicIPAddressName,copyIndex())]",
"location": "[resourceGroup().location]",
"copy": {
"name": "PublicIPLoop",
"count": "[parameters('vmCount')]",
"mode":"Parallel"
},
"tags": {
"displayName": "[concat(variables('publicIPProperty').publicIPAddressName,copyIndex())]"
},
"properties": {
"publicIPAllocationMethod": "[variables('publicIPProperty').publicIPAddressType]",
"dnsSettings": {
"domainNameLabel": "[concat(parameters('dnsNamePrefix'),copyIndex())]"
}
}
},

Handling resource dependencies

‘dependsOn’ keyword helps to ensure the resource dependency resolution.

{
"comments": "Create NIC VMs",
"apiVersion": "2016-03-30",
"type": "Microsoft.Network/networkInterfaces",
"name": "[concat(variables('networkProperty').nicName,copyIndex())]", 
"location": "[resourceGroup().location]",
"copy": {
"name": "NICLoop",
"count": "[parameters('vmCount')]",
"mode":"Parallel"
},
"tags": {
"displayName": "[concat(variables('networkProperty').nicName,copyIndex())]" 
},
"dependsOn": [
"[resourceId('Microsoft.Network/publicIPAddresses/', concat(variables('publicIPProperty').publicIPAddressName,copyIndex()))]",
"[resourceId('Microsoft.Network/virtualNetworks/', variables('networkProperty').virtualNetworkName)]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses', concat(variables('publicIPProperty').publicIPAddressName,copyIndex()))]"
},
"subnet": {
"id": "[variables('subnetRef')]"
}
}
}
]
}
},

We will discuss more about the ARM functions and property in upcoming post, where we will write more complex deployment.

Deployment using PowerShell

Before starting the deployment you need to run ‘Add-AzureRMAccount’ PowerShell to login and set the correct subscription against which you would like to have deployment.

Deployment Result

Get Complete Code

Best practices for creating Azure Resource Manager templates


Please do let me know your thoughts/ suggestions/ question in disqus section.


Related Posts

About Ajeet Chouksey

With a robust background spanning more than 18 years, I am an adept Azure and Azure DevOps architect and engineer, dedicated to crafting Azure-centric solutions that prioritize customer requirements and agile methodologies. My expertise encompasses steering extensive cloud migration initiatives and advocating for Azure best practices, all aimed at streamlining costs and steering multinational teams towards success. Fueled by a passion for technological innovation, I am committed to perpetual learning, constantly advancing my proficiency in Azure, AI, MLOps, and Product Management to stay at the forefront of the industry..