The most important point is when you are deleting any of the Resource Groups, all the resources belonging to that particular Resource Group along with the Resource Group will get deleted permanently. So, you must be very much careful before deleting any of the resource Groups.
Make sure before deleting the Resource Group, that you are reading the warning message that says below.
“Warning! Deleting the “demogroup” resource group is irreversible. The action you’re about to take can’t be undone. Going further will delete this resource group and all the resources in it permanently.”
So, note that it is not possible to recover or restore a deleted Resource Group in Azure. The action can’t be undoneand is an irreversible action.
But to avoid this scenario in the future all you need to do is identify all the important Resource Groups that contain critical Azure resources and then Lock those Resource Groups.
As an administrator, you can lock an Azure subscription, resource group, or resource to protect them from accidental user deletions and modifications. The lock overrides any user permissions.
You can set locks that prevent either deletions or modifications. In the portal, these locks are called Delete and Read-only
To Lock your Azure Resource Groups, you just need to follow the below quick instructions.
Search for Resource Groups and click on the search result Resource Groups.
Now, you will be able to see the lists of Resource Groups that you have created. Click on the specific Resource Group that you wish to Lock.
On the Resource Group page, click on the Locks link from the left navigation that is present under Settings.
Click on the + Add button to create a Lock for that Resource Group you wish to delete.
On the Add lock window, Provide the below details.
Lock name: Provide a meaningful name for your Lock.
Lock type: Select the Lock type read-only or delete based on your requirement.
Notes: Provide a note which is optional.
Click on the Ok button to create the Lock.
Now when you will try to delete the Resource Group, it won’t allow you and will show you a message
“The Resource Group is locked and can’t be deleted. Click here to manage locks for this Resource Group.”
To edit/remove the lock, select the edit/delete button.
This way you can protect your Azure Resource Group from an accidental deletion or modification in Azure Portal.
Once a resource has been locked, the resource lock must first be removed before the resource can be modified or deleted.
How to recover deleted Resource Group Azure
You can just try the following as a workaround.
You can try raising a ticket to Microsoft to restore it back. Provide as much detail as you can about the deleted resources, including their resource IDs, types, and resource names. Note: Recovery of deleted resources is not possible under all circumstances. A support engineer will investigate your scenario and advise you whether it's possible.
Some resource types support soft delete. You might have to configure soft delete before you can use it. For more information about enabling soft delete, see the documentation for Azure Key Vault, Azure Backup, and Azure Storage.