Last active
January 28, 2022 07:05
-
-
Save jeremybeavon/bd944f93564a4092a08acd6815eff9ad to your computer and use it in GitHub Desktop.
ARM template for deploying multiple VMs from a custom image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", | |
"contentVersion": "1.0.0.0", | |
"parameters": { | |
"VnetResourceGroup": { | |
"type": "string" | |
}, | |
"VnetName": { | |
"type": "string" | |
}, | |
"SubnetName": { | |
"type": "string" | |
}, | |
"VMImageName": { | |
"type": "string" | |
}, | |
"AdminUsername": { | |
"type": "string", | |
"metadata": { | |
"description": "Admin username for VM" | |
} | |
}, | |
"AdminPassword": { | |
"type": "securestring", | |
"metadata": { | |
"description": "Admin password for VM" | |
} | |
}, | |
"VMNames": { | |
"type": "array", | |
"metadata": { | |
"description": "Number of VMs to deploy, limit 5 since this sample is using a single storage account" | |
} | |
} | |
}, | |
"resources": [ | |
{ | |
"type": "Microsoft.Network/networkInterfaces", | |
"name": "[concat(parameters('VMNames')[copyIndex()], '-nic')]", | |
"apiVersion": "2016-03-30", | |
"location": "[resourceGroup().location]", | |
"copy": { | |
"name": "nicLoop", | |
"count": "[length(parameters('VMNames'))]" | |
}, | |
"properties": { | |
"ipConfigurations": [ | |
{ | |
"name": "ipconfig1", | |
"properties": { | |
"privateIPAllocationMethod": "Dynamic", | |
"subnet": { | |
"id": "[concat(resourceId(parameters('VnetResourceGroup'),'Microsoft.Network/virtualNetworks/subnets',parameters('VnetName')),'/subnets/',parameters('subnetName'))]" | |
} | |
} | |
} | |
] | |
} | |
}, | |
{ | |
"type": "Microsoft.Compute/virtualMachines", | |
"name": "[parameters('VMNames')[copyIndex()]]", | |
"apiVersion": "2016-04-30-preview", | |
"location": "[resourceGroup().location]", | |
"copy": { | |
"name": "virtualMachineLoop", | |
"count": "[length(parameters('VMNames'))]" | |
}, | |
"dependsOn": [ | |
"nicLoop" | |
], | |
"properties": { | |
"hardwareProfile": { | |
"vmSize": "Standard_D1_v2" | |
}, | |
"osProfile": { | |
"computerName": "[parameters('VMNames')[copyIndex()]]", | |
"adminUsername": "[parameters('AdminUsername')]", | |
"adminPassword": "[parameters('AdminPassword')]" | |
}, | |
"storageProfile": { | |
"imageReference": { | |
"id": "[resourceId(parameters('VnetResourceGroup'), 'Microsoft.Compute/images', parameters('VMImageName'))]" | |
}, | |
"osDisk": { | |
"createOption": "FromImage", | |
"managedDisk": { | |
"storageAccountType": "Standard_LRS" | |
} | |
} | |
}, | |
"networkProfile": { | |
"networkInterfaces": [ | |
{ | |
"id": "[resourceId('Microsoft.Network/networkInterfaces',concat(parameters('VMNames')[copyIndex()], '-nic'))]" | |
} | |
] | |
} | |
} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment