Terraform Azure 托管磁盘 C 和 D 驱动器

Terraform Azure managed disk C & D drives

我有一个 500GB 的 Azure 托管磁盘,在虚拟机上使用时有一个 126GB C 驱动器和一个 399GB D 驱动器。这是在 Terraform 的 azurerm_virtual_machine 资源中通过以下方式创建的:

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

我正在通过以下方式获取此副本以在另一台虚拟机上使用:

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"

}

然后我通过以下方式将副本安装到新虚拟机上:

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

但是,当我打开新的虚拟机时,只有C盘包含在副本中。怎么也复制到D盘?我尝试使用 azurerm_virtual_machine_data_disk_attachment 资源附加托管磁盘的相同资源 ID,但出现以下错误(这很有意义):

│ 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'."

没想到C盘只分配了126GB,还有374GB未分配space。解决方案是扩展 C 驱动器以使用未分配的 space(总共提供 500GB)。令我困惑的一点是存在一个 500GB D 驱动器,我现在意识到它是映像的一部分,而不是托管磁盘。