Vault Cannot Be Deleted As There Are Existing Resources Within The Vault

Vault Cannot Be Deleted As There Are Existing Resources Within The Vault

In this Azure Article, we will discuss how to fix the error, ” Vault Cannot Be Deleted As There Are Existing Resources Within The Vault “. This error I got when I was trying to delete one of the Recovery Services vaults. Along with this, we will also discuss the below topics

  • How to delete azure recovery services vault
  • How to delete azure recovery services vault using PowerShell

Vault Cannot Be Deleted As There Are Existing Resources Within The Vault

Recently, I was trying to clear the unused Azure resources to reduce the cost, When I tried to delete one of the Azure Recovery Services vaults, it didn’t allow me to delete and I got the error “Vault cannot be deleted as there are existing resources within the vault

The completely error message was as below

Vault cannot be deleted as there are existing resources within the vault: Please ensure all containers have been unregistered from the vault and all private endpoints associated with the vault have been deleted, and retry the operation. For more details, see https://aka.ms/AB-AA4ecq5

I followed the below steps to delete the Azure Recovery Service vault. My Azure Recovery Service vault name was vault938 that I was trying to delete.

How to delete azure recovery services vault

Navigate to the Recovery Services vault, click on the Recovery Services vault that you want to delete. On the Recovery Services vault page, click on the Delete button.

Vault Cannot Be Deleted As There Are Existing Resources Within The Vault

Then I clicked on the Yes button for the confirmation

Azure vault cannot be deleted

I got the below Vault deletion error as “Vault Cannot Be Deleted As There Are Existing Resources Within The Vault” as shown below.

azure vault deletion error

Now the reason I got this error is that there is a Backup item for the Azure Virtual Machine that is attached to this Recovery Services vault. To check that, click on the Backup items link under Protected items on the Recovery Services vault page.

Azure Recovery Service vault deletion Error

After clicking on the Backup items, you can see for the Azure Virtual Machine, the Backup Item count is 1. Click on the Azure Virtual Machine.

Azure recovery services vault soft delete

You can see below, this the Virtual Machine backup instance that is attached to the Azure Recovery Services vault.

Recovery services vault soft delete

Now to fix this error, what you need to do is, you need to delete the Backup Items(Azure Virtual Machine).

To delete this, select the Azure Virtual Machine back up instance, click on the three dots (…) or you can right-click on that for the same options and then click on the stop backup option.

remove vm from recovery services vault

Now click on the Stop Backup button to confirm the Stop Backup functionality.

azure remove vm from recovery services vault

Now you can see the Stopping backup functionality completed successfully.

remove vm from backup azure

Now after stopping the backup, select the Azure Virtual Machine back up instance, click on the three dots (…) or you can right-click on that for the same options and then click on the Delete backup data option

how to remove vm from backup azure

Type the name of the Backup item and then click on the Delete button to delete the Backup data.

Note: An important thing to note here is the name of the Backup Item is case sensitive and you need to enter exactly the same name of the Backup Data as it is.

How to delete azure backup vault

You can see below it deleted the backup data for the virtual machine successfully.

azure vault cannot be deleted as there are existing resources within the vault

See here, The restore points for this backup item have been deleted and retained in the soft delete state and will be available for 13 more days to recover. After which they will be permanently deleted. That means even though you deleted the Backup data but it is available still for 13 more days in soft delete state then after it will delete permanently.

deleting a recovery services vault

You can see below the Backup items (Azure Virtual Machine) is in Soft delete state.

force delete recovery services vault

Now again if you will try to delete the Azure Recovery Services vault, it will not allow you to delete and you will get the below error

Recovery Services vault cannot be deleted as there are backup items in the soft-deleted state in the vault. The soft-deleted items are permanently deleted after 14 days of the delete operation. Please try vault deletion after the backup items are permanently deleted and there is no item in the soft-deleted state left in the vault. For more information, refer

So now you have two options to delete the Azure Recovery Services vault to fix the error “Vault Cannot Be Deleted As There Are Existing Resources Within The Vault”

Option-1: You need to wait for the 14 days and then after it will completely delete the soft delete backup data automatically, after that, you can try deleting the Azure Recovery Services vault, it will allow you to delete this time without any issue.

Option-2: If you want to permanently delete the soft delete data immediately instead of waiting for the 14 days, then you need to follow the below steps to do that. Then after you can able to delete Azure Recovery Services vault immediately without any issue.

The first step is to disable the Soft delete option in the Azure Portal, to do that. Click on the Properties under settings option on the Recovery Services vault page and then click on the Security Settings —> Update link.

disable soft delete azure key vault

On the Security Settings page, Select the Disabled button for the Soft Delete (For Azure Virtual Machines) option and then click on the Save button to update the changes.

As mentioned below, you can see once you disabled the Soft delete option, all future deletes will be immediate and will not have soft delete protection.

how to disable soft delete azure key vault

Now the settings is updated.

azure soft delete option disable

Now the Soft Delete (For Azure Virtual Machines) option is disabled so now on the next step, select the Soft delete backup data and click on the three dots (…), click on the Undelete option.

Azure soft delete disable

Click on the Undelete button to confirm the undelete functionality.

soft delete azure vm

Now if you will try deleting the backup data, you can able to delete the backup data with out any issue.

disable soft delete azure backup

Just to verify, you can see below, the backup data is deleted successfully.

how to disable soft delete azure backup

Since there is no backup data present for the Azure Virtual Machine, so now if you try deleting the Azure Recovery Services vault, you can able to delete it without any issue.

Azure turn off soft delete

Click on the Yes button to confirm the Deletion process

Azure turn off soft delete option

You can see below the Recovery Services vault successfully deleted with out any issue.

azure backup disable soft delete

Just to reconfirm you can see below there is no Recovery services vault present.

recovery services vault disable soft delete

This is how we can fix the error “Vault Cannot Be Deleted As There Are Existing Resources Within The Vault” and This is how we can delete azure recovery services vault using the Azure Portal.

How to delete azure recovery services vault using PowerShell

We discussed above How to delete azure recovery services vault using Azure Portal. Now let’s discuss How to delete azure recovery services vault using PowerShell.

You can use below PowerShell cmdlet to identify the items that are in soft-deleted state

Get-AzRecoveryServicesBackupItem -BackupManagementType AzureVM -WorkloadType AzureVM -VaultId $myOldVaultID | Where-Object {$_.DeleteState -eq "ToBeDeleted"}

$newItem = Get-AzRecoveryServicesBackupItem -BackupManagementType AzureVM -WorkloadType AzureVM -VaultId $myOldVaultID -Name MyNewVM
delete azure recovery services vault using PowerShell

Now you need to reverse the deletion operation that was performed when the soft-delete was enabled using the below PowerShell cmdlet

Undo-AzRecoveryServicesBackupItemDeletion -Item $newItem -VaultId $myOldVaultID -Force
How to delete azure recovery services vault using PowerShell

Soft-delete is now disabled, now use the below PowerShell cmdlet for the deletion operation

Disable-AzRecoveryServicesBackupProtection -Item $newItem -RemoveRecoveryPoints -VaultId $myOldVaultID -Force
delete azure recovery services vault PowerShell

This is how we can delete Azure recovery services vault using PowerShell as discussed above.

You may also like going through the below tutorials

Conclusion

Well, in this tutorial, we discussed how to fix the error “Vault Cannot Be Deleted As There Are Existing Resources Within The Vault”. Along with this we also discussed How to delete Azure recovery services vault using the Azure Portal and finally, we discussed, How to delete Azure recovery services vault using PowerShell.

Leave a Comment