hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.52k stars 4.6k forks source link

azurerm_managed_disk created from a snapshot but trying to use restore from backup #22068

Open mpjtaylor opened 1 year ago

mpjtaylor commented 1 year ago

Is there an existing issue for this?

Community Note

Terraform Version

1.4.4

AzureRM Provider Version

3.5.8

Affected Resource(s)/Data Source(s)

azurerm_managed_disk

Terraform Configuration Files

resource "azurerm_managed_disk" "disk" {
  name                          = var.disk_name
  resource_group_name           = var.resource_group_name
  location                      = var.location
  storage_account_type          = var.storage_account_type
  create_option                 = var.create_option
  disk_size_gb                  = var.disk_size_gb
  source_resource_id            = var.source_resource_id
}

Debug Output/Panic Output

Error: creating/updating Managed Disk "name_Data_Snapshot" (Resource Group "group"): performing CreateOrUpdate: disks.DisksClient#CreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: Code="InvalidParameter" Message="Required parameter 'sourceUri' is missing (null)." Target="sourceUri"
with azurerm_managed_disk.disk

Expected Behaviour

Deploy a disk using a snapshot with create option copy and source_resource_id of the snapshot backup the disk azure recovery services vault restore the disk using azure recovery services vault this gives the VM new disks with new names Re-Deploy the disk using the Restore option and setting the source_resource_id to the id of the recovered disk.

Actual Behaviour

Error applying, is this possible? how can Restore option be used..

Steps to Reproduce

terraform apply Deploy a disk using a snapshot with create option copy and source_resource_id of the snapshot

Important Factoids

No response

References

(https://github.com/hashicorp/terraform-provider-azurerm/pull/3598)

mpjtaylor commented 1 year ago

Seems I found the some help here : https://github.com/hashicorp/terraform-provider-azurerm/pull/3598 az disk show -g rg -n disk --query creationData

Set "sourceResourceId": "/subscriptions/xx/resourceGroups/AzureBackupRG_northeurope_1/providers/Microsoft.Compute/restorePointCollections/AzureBackup_xxx/restoreP oints/AzureBackup_20230606_034345/disks/vm_osdisk?id=5f2418b2-643e-43cb-8299-47ba47871050" Changing property 'dataDisk.managedDisk.id' is not allowed.", "target": "dataDisk.managedDisk.id

But what Id am i mean to use ?

mpjtaylor commented 1 year ago

can someone provide a restore example as i cannot get this to work at all !

myc2h6o commented 1 year ago

@mpjtaylor the disk created by the Restore option is a new disk, thus you are not able to update the managed disk resource. Instead, you would need to use a new azurerm_managed_disk resource and import the new disk.

mpjtaylor commented 1 year ago

returning to this as I still have an issue with azurerm_windows_virtual_machine or azurerm_linux_virtual_machine and OS Disks, should i raise this as a new feature request the ability to change the create_option from Empty to Restore and specify source_resource_id

benlavender commented 6 months ago

I also have an issue with this resource. The error I get is complaining that the source_resource_id is not in the format of subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/restorePointCollections/{restorePointCollectionName}/restorePoints/{restorePointName}/disks/{sourceDiskName}?id={restorePointId}

However I don't believe this format is in use any more as either PS command Get-AzRecoveryServicesBackupRecoveryPoint or Azure CLI command az backup recoverypoint list both come back with a recovery point ID of something like "8562018518480576656" or longer ID format but that also doesn't match the format required.

Is it simply out of date and needs updating in the resource?