5

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.
Piotr Perak
  • 10,718
  • 9
  • 49
  • 86
  • I cannot delete an Azure Form Recognizer resource either. I'm getting the same error. Did you figure this one out? – Ryan May 27 '21 at 02:57
  • 1
    No, it just worked when I tried it yesterday. I was able to deploy it again. – Piotr Perak May 27 '21 at 13:00
  • Did it take a day? I just tried it 1 day after and it's still not working – Ryan May 27 '21 at 16:47
  • 1
    More than that. I asked question on Thursday and it probably started to work on Tuesday. I probably didn't check on Monday. When I asked Azure support on Twitter they gave me this link: https://learn.microsoft.com/en-us/rest/api/apimanagement/2020-06-01-preview/deletedservices/purge . It's for wrong service but maybe such endpoint exists for Text analytics too. – Piotr Perak May 28 '21 at 08:55

4 Answers4

7

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
mat roberts
  • 144
  • 3
2

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

Ryan
  • 4,354
  • 2
  • 42
  • 78
  • This is how I removed it using Az PowerShell: `Invoke-AzRestMethod -Path "/subscriptions/{subscriptionId}/providers/Microsoft.CognitiveServices/locations/{location}/resourceGroups/{rgName}/deletedAccounts/{accountName}?api-version=2021-04-30" -Method "DELETE"` – chivano Jun 22 '21 at 11:41
  • az resource delete needs a --ids arg and didn't remove from the holding area `az resource delete --ids /subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/resource-group/providers/microsoft.cognitiveservices/accounts/resource-account` – Slate Jan 21 '22 at 17:24
1

Only this worked for me:

az cognitiveservices account purge -l northeurope -n your-service-name -g your-rg
Blink
  • 1,408
  • 13
  • 21
0

Thanks @chivano This worked for me Az PowerShell:

Invoke-AzRestMethod -Path "/subscriptions/{subscriptionId}/providers/Microsoft.CognitiveServices/locations/{location}/resourceGroups/{rgName}/deletedAccounts/{accountName}?api-version=2021-04-30" -Method "DELETE"
James Z
  • 12,209
  • 10
  • 24
  • 44