Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to purge soft-deleted Text analytics?

To test ARM templates we first deploy them on test resource group. At 7PM those resource groups are automatically deleted. Yesterday it was working fine and today I can no longer deploy to the same test resource group name. I have not changed templates for a long time.

I'm not able to find this soft-deleted service anywhere in Azure Portal and don't know how to purge it.

14:43:17 - Error: Code=FlagMustBeSetForRestore; Message=An existing resource with ID
     | '/subscriptions/GUID/resourceGroups/myRG/providers/Microsoft.CognitiveServices/accounts/my-ta-zneztme4oqjb2' has been
     | soft-deleted. To restore the resource, you must specify 'restore' to be 'true' in the property. If you don't want to restore existing resource, please purge it first.
like image 236
Piotr Perak Avatar asked May 20 '21 12:05

Piotr Perak


3 Answers

Here a link to the rest endpoints you can call against cognitive services

There is an endpoint to list the deleted cognitive services which you can call like this:

az rest --method get --header 'Accept=application/json' -u 'https://management.azure.com/subscriptions/$SubscriptionId/providers/Microsoft.CognitiveServices/deletedAccounts?api-version=2021-04-30'

It returns a json structure listing of the deleted cognitive services. Each deleted service has an id property, which is the thing you pass to the delete method:

az resource delete --ids $id
like image 173
mat roberts Avatar answered Oct 23 '22 20:10

mat roberts


I had to contact Microsoft support on this. It's still not 100% working for me yet but perhaps it might for someone else.

To purge the recently deleted resource from the undo holding area (and free up the name for new resources), use one of the following methods:

RestAPI

DELETE https://management.azure.com/subscriptions/{subscirptionId}/providers/Microsoft.CognitiveServices/locations/{location}/resourceGroups/{resourceGroup}/deletedAccounts/{accountName}?Api-Version=2021-04-30

CLI

az resource delete /subscriptions/{subscirptionId}/providers/Microsoft.CognitiveServices/locations/{location}/resourceGroups/{resourceGroup}/deletedAccounts/{accountName}

Powershell

Remove-AzResource -ResourceId /subscriptions/{subscirptionId}/providers/Microsoft.CognitiveServices/locations/{location}/resourceGroups/{resourceGroup}/deletedAccounts/{accountName} -ApiVersion 2021-04-30

like image 27
Ryan Avatar answered Oct 23 '22 22:10

Ryan


Only this worked for me:

az cognitiveservices account purge -l northeurope -n your-service-name -g your-rg
like image 1
Blink Avatar answered Oct 23 '22 22:10

Blink