IaC - ARM Template Deployment (HOL)
ARM Template hands-on lab.
- 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.
- All the VMs will have an additional data disk.
- Virtual network with one subnet.
- Create Azure SQL server instance along with database.
- All of these resources will reside inside a single resource group.
- 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
Best practices for creating Azure Resource Manager templates
Please do let me know your thoughts/ suggestions/ question in disqus section.
Related Posts
- Azure Bastion
- Secure secretes in Azure DevOps Pipelines
- Integration of Azure Backup into VM create experience
- Azure Archive Storage
- Auto-shutdown RM VM