Reputation: 27
I am using copy to create multiple VM's and want to have multiple datadisks for each vm. I know i can do it this way:
{
"name": "[concat('dataDisk-',parameters('vm-name'),'-0',copyIndex(1))]",
"diskSizeGB": "[parameters('dataDisksize')]",
"lun": 0,
"createOption": "Empty"
},
{
"name": "[concat('dataDisk1-',parameters('vm-name'),'-0',copyIndex(1))]",
"diskSizeGB": "[parameters('dataDisksize')]",
"lun": 1,
"createOption": "Empty"
}
Now I have to create 20 disks with the same name and this doesn't seem to be good workaround. Getting issue with disk name while using copy. For my case i can use the same disksize for all 20 disks
Upvotes: 0
Views: 600
Reputation: 5516
Now I have to create 20 disks with the same name and this doesn't seem to be good workaround. Getting issue with disk name while using copy.
Creating multiple disks using same name is impossible. you need concat
either copyindex
values to disk name or the VMnames
to the Names of the disk..
In our template we have used the copy function
block in the below manner to deploy multiple disks for a single virtual Machine & we have tested this in our local environment which is working fine.
Here is the ARM template that we have created :
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"dataDiskCount": {
"type": "int","minvalue" : 1,"maxValue" :20,"defaultValue" : 4,
"metadata": {
"description": "number of data disks."
}
}
},
"variables": {}
"resources": [
{
"copy": [
{
"name": "dataDisks",
"count": "[parameters('dataDiskCount')]",
"input": {
"diskSizeGB": "20",
"lun": "[copyIndex('dataDisks')]",
"createOption": "Empty",
"name":"[concat('disk',copyIndex('dataDisks'),'dk')]"
}
}
},
"outputs": {}
}
Here is the sample output screen shot for reference:
Upvotes: 0
Reputation: 938
You can use the copy element to repeat properties:
"copy": [
{
"name": "dataDisks",
"count": "[parameters('numberOfDataDisks')]",
"input": {
"lun": "[copyIndex('dataDisks')]",
"createOption": "Empty",
"diskSizeGB": 1023
}
}
]
More information here: https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/copy-properties
Upvotes: 1