Attach disk to only one node in azure

113 Views Asked by At

I'm using ARM template to create 4 SHARED disks and 3 VMs. Is there a way to attach these disks only to one node ?

below is my code for disk creation,

{
    "type": "Microsoft.Compute/disks",
    "apiVersion": "2018-06-01",
    "name": "[concat(variables('vmName'),'-datadisk1')]",
    "location": "[resourceGroup().location]",
    "sku": {
        "name": "Premium_LRS"
    },
    "properties": {
        "creationData": {
            "createOption": "Empty"
        },
        "diskSizeGB": 1024,
        "maxShares": 5
    }
}

below is the code for VM creation,

{
    "type": "Microsoft.Compute/virtualMachines",
    "apiVersion": "2018-10-01",
    "name": "[variables('vmName')]",
    "location": "[resourceGroup().location]",
    "dependsOn": [
    "[resourceId('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
    "[resourceId('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
    "[resourceId('Microsoft.Compute/disks/', concat(variables('vmName'),'-datadisk1'))]"
    ],
    "properties": {
        "hardwareProfile": {...},
        "osProfile": {...},
        "storageProfile": {
            "imageReference": {...},
            "osDisk": {
                "name": "osdisk",
                "vhd": {...},
                "caching": "ReadWrite",
                "createOption": "FromImage"
            },
        },
        "networkProfile": {...},
        "diagnosticsProfile": {...}
    }
}

since I'm attaching multiple disks adding dataDisks to properties in VM resource will attach disks to all VMs parallelly which will result in failure (shared disks cannot be attached parallelly to multiple VMs).

Is there a way to achieve attaching shared disk to only one VM (through VM resource) or after all VMs are created ?

2

There are 2 best solutions below

0
On

I would create additional step in ARM with adding Powershell Deployment Script

But you will need service principal with abbilities to modify the disks.

0
On

In the Azure Template, it seems you only can add the dataDisks block to attach data disks to the one VM. And if you also want to create multiple VMs, then you need to separate the VM that you want to attach multiple data disks to into a single resource and add the data disks to that VM. There is also one thing you need to pay attention to. You need to check the VM size to make sure if the VM can be attached with multiple data disks as you want. The VM size limits the number of the data disks.