Detaching previous data disk while adding new Data Disk to Virtual Machine .

Dnyaneshwar Surywanshi 156 Reputation points
2021-02-02T08:11:17.287+00:00

I am attaching new data disk to my windows VM but my previously added disk has been removed (Dettached) automatically so how can I solve this problem please help me on this .
Below is my ARM template for Adding new disk to VM :

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"type": "String"
},
"diskName": {
"type": "String"
}
},
"resources": [{
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2019-07-01",
"name": "[parameters('vmName')]",
"location": "[resourceGroup().location]",
"properties": {

            "storageProfile": {
                "dataDisks": [{
                        "lun": 0,
                        "name": "[parameters('diskName')]",
                        "createOption": "attach",
                        "managedDisk": {
                            "id": "[resourceId('Microsoft.Compute/disks/', parameters('diskName'))]"
                        }
                    }
                ]
            }
        },
        "dependsOn": ["[resourceId('Microsoft.Compute/disks/', parameters('diskName'))]"]
    }, {
        "type": "Microsoft.Compute/disks",
        "apiVersion": "2018-06-01",
        "name": "[parameters('diskName')]",
        "location": "[resourceGroup().location]",
        "sku": {
            "name": "Standard_LRS"
        },
        "properties": {
            "creationData": {
                "createOption": "Empty"
            },
            "diskSizeGB": 1023
        }
    }

]

}

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,254 questions
Azure Disk Storage
Azure Disk Storage
A high-performance, durable block storage designed to be used with Azure Virtual Machines and Azure VMware Solution.
582 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Kasun Rajapakse 351 Reputation points
    2021-02-02T16:36:26.533+00:00

    Make sure the Lun number is different from the existing data disk lun number


  2. deherman-MSFT 34,021 Reputation points Microsoft Employee
    2021-02-04T17:43:15.567+00:00

    @Dnyaneshwar Surywanshi
    Since you are not specifying the previously attached data disk in this ARM template it is getting detached, you need to specify both disks in your ARM template. I see you also asked this on Stack Overflow and got an answer for this. Linking to that thread incase others face this issue in the future.


  3. Carl Trevett 1 Reputation point
    2021-04-06T09:36:32.457+00:00

    @Dnyaneshwar Surywanshi did you ever find an answer to your question? I am trying to figure out the same as I do not want to declare existing data disks only attach a new one

    0 comments No comments