'Terraform Azure managed disk C & D drives

I have an Azure managed disk of 500GB that when used on a virtual machine has a 126GB C drive and a 399GB D drive. This was created in Terraform in the azurerm_virtual_machine resource via:

  storage_os_disk {
    name              = "diskname"
    disk_size_gb      = "500"
    caching           = "ReadWrite"
    create_option     = "FromImage"
    managed_disk_type = "Standard_LRS"    
    os_type           = "Windows" 
  }

I am taking a copy of this for use on another virtual machine via:

resource "azurerm_managed_disk" "copy" {
  name                 = "diskcopy"
  location             = var.rglocation
  resource_group_name  = var.rgname
  storage_account_type = "Standard_LRS"
  create_option        = "Copy"
  source_resource_id   = "/subscriptions/xxxxx/originalos"

}

I am then mounting the copy on the new virtual machine via:

  storage_os_disk {
    name              = "diskname"
    caching           = "ReadWrite"
    create_option     = "Attach"
    managed_disk_id   = var.manageddiskid
    os_type           = "Windows" 
  }

However, when I open the new virtual machine only the C drive is included in the copy. How can I also copy the D drive? I have tried to use the azurerm_virtual_machine_data_disk_attachment resource to attach the same resource ID of the managed disk but get the following error (which makes sense):

│ Error: updating Virtual Machine "Virtual Machine: (Name \"xxx\" / Resource Group \"xxx\")"  with Disk "xxx": compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=409 -- Original Error: Code="ConflictingUserInput" Message="Disk 'xxx' cannot be attached as the disk is already owned by VM 'xxx'."


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source