Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JeffBrownTech/33494b83a9e342d00371f123b2a1d3ff to your computer and use it in GitHub Desktop.
Save JeffBrownTech/33494b83a9e342d00371f123b2a1d3ff to your computer and use it in GitHub Desktop.
ARM Template - Use Copy Loop to Deploy Multiple Data Disks on a Virtual Machine
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"dataDiskCount": {
"type": "int",
"metadata": {
"description": "Number of data disks to add to the VM."
}
}
},
"resources": [
{
"name": "ubuntuVM-nic",
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2019-11-01",
"location": "[resourceGroup().location]",
"properties": {
"ipConfigurations": [
{
"name": "ipconfig",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"subnet": {
"id": "[resourceId('network-rg', 'Microsoft.Network/virtualNetworks/subnets', 'vnet1', 'snet1')]"
}
}
}
]
}
},
{
"name": "ubuntuVM",
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2019-07-01",
"location": "[resourceGroup().location]",
"dependsOn": [
"[resourceId('Microsoft.Network/networkInterfaces', 'ubuntuVM-nic')]"
],
"properties": {
"hardwareProfile": {
"vmSize": "Standard_B1s"
},
"osProfile": {
"computerName": "ubuntuVM",
"adminUsername": "cloud_admin",
"adminPassword": "N0t@RealPa$$w0rd"
},
"storageProfile": {
"imageReference": {
"publisher": "Canonical",
"offer": "UbuntuServer",
"sku": "16.04-LTS",
"version": "latest"
},
"osDisk": {
"name": "ubuntuVM-OSDisk",
"caching": "ReadWrite",
"createOption": "FromImage"
},
"copy": [
{
"name": "dataDisks",
"count": "[parameters('dataDiskCount')]",
"input": {
"lun": "[copyIndex('dataDisks')]",
"name": "[concat('ubuntuVM-datadisk', copyIndex('dataDisks'))]",
"createOption": "Empty",
"diskSizeGB": 32
}
}
]
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', 'ubuntuVM-nic')]"
}
]
}
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment