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

As Technology Architect, Ajeet has over 12+ years of industry experience delivering enterprise solutions on the Microsoft Platform. Ajeet is passionate, certified technologist, blogger and community contributor. His specialisms are Azure IaaS/PaaS, Automation, DevOps, Agile based development processes supporting distributed teams (on shore & off shore), designing and implementing the appropriate infrastructure and platform solutions to meet the functional, operational, and deployment requirements throughout the solution life-cycle. Ajeet is member of various technical communities and discussion groups. He also conducted many boot camps on Azure and DevOps.