Retrieve OS Disk ID for Azure Site Recovery

Hi,

I have created a azurerm_windows_virtual_machine with three managed disks. I’m trying to play with site replication but in the managed_disk{} I can’t target the OS disk id.

The error I receive is:
Protection couldn’t be enabled for Azure
virtual machine ‘…’ as the OS disk is not specified."

I’ve reviewed Terraform Registry and the example is for
azurerm_virtual_machine rather than azurerm_windows_virtual_machine.

I did have a play azurerm_windows_virtual_machine.vm.os_disk[0] and other methods but I can’t find .id. Although, I can for the attached managed disks.

Any ideas :smiley: ?

Thanks,

Brad.

I had to manually add the OS disk after VM creation

# Adding OS disk so TF can see it
data "azurerm_managed_disk" "vm_osdisk" {
  name                = azurerm_windows_virtual_machine.vm.os_disk[0].name
  resource_group_name = azurerm_resource_group.rg_primary.name
}

Then in the managed disk block for azurerm_site_recovery_replicated_vm I did the below using the lower function.

  managed_disk {
    disk_id = lower(data.azurerm_managed_disk.vm_osdisk.id)
    staging_storage_account_id = azurerm_storage_account.storage_asr.id
    target_resource_group_id = azurerm_resource_group.rg_secondary.id
    target_disk_type = azurerm_windows_virtual_machine.vm.os_disk[0].storage_account_type
    target_replica_disk_type = azurerm_windows_virtual_machine.vm.os_disk[0].storage_account_type
  }

Hope this helps someone.