0
votes

TL;DR:

Is there a way to delete all resources in resource group except for Complete-mode deploy with empty template and manual step-by-step deletion from web interface?

Delete resource group is not an option (access rights: Contributor, not owner)

Details:

I am trying to completely clean up resource group in AZURE.

Delete resource group is not an option (access rights: Contributor, not owner)

Most elegant and obvious way to do this (also described in some articles) is to perform Complete deployment with "empty" deployment template:

New-AzureRmResourceGroupDeployment -Mode Complete -ResourceGroupName RG_NAME -TemplateFile .\empty.json

with the following empty.json:

{ "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "2018-02-15", "parameters": {}, "variables": {}, "resources": [], "outputs": {} }

But... This works sometimes. Even not most of the time.

Once it got an infinite loop trying to get SQL Server deleted, failed and trying to delete again. After 20 minutes of waiting I went to events and found about 100 events like

"Delete SQL Server Started" ... "Accepted" ... "Failed" ... "Started" ... "Accepted" ... "Failed" ... ...

You got the idea.

Other times it works fine.

So, the question is: is there a way to delete all resources in resource group except for Complete-mode deploy with empty template and manual step-by-step deletion from web interface?

Example that seems to be repeatable

  1. Try to deploy SQL server with the following template (it will fail with password complexity validation)

    { "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "2018-02-19", "parameters": { "location": { "type": "string", "defaultValue": "West Europe" }, "dbAdministratorLogin": { "type": "string", "defaultValue": "sysadm" }, "dbAdministratorPassword": { "type": "string" , "defaultValue": "123123" }, }, "variables": { "dbServerName": "dka-tst-sto-sql-srv", "databaseName": "dka-tst-sto-sql" }, "resources": [ {"comments": "server and database. Database - child resource of a server", "type": "Microsoft.Sql/servers", "name": "[variables('dbServerName')]", "apiVersion": "2015-05-01-preview", "location": "[parameters('location')]", "properties": { "administratorLogin": "[parameters('dbAdministratorLogin')]", "administratorLoginPassword": "[parameters('dbAdministratorPassword')]", "version": "12.0" }, "resources": [{ "type": "databases", "name": "[variables('databaseName')]", "apiVersion": "2014-04-01-preview", "location": "[parameters('location')]", "properties": { "collation": "SQL_Latin1_General_CP1_CI_AS", "edition": "Standard", "maxSizeBytes": "268435456000", "requestedServiceObjectiveId": "f1173c43-91bd-4aaa-973c-54e79e15235b", "sampleName": "", "zoneRedundant": false }, "dependsOn": [ "[concat('Microsoft.Sql/servers/', variables('dbServerName'))]" ] }, { "type": "firewallrules", "name": "AllowAllWindowsAzureIps", "apiVersion": "2014-04-01-preview", "location": "[parameters('location')]", "properties": { "endIpAddress": "0.0.0.0", "startIpAddress": "0.0.0.0" }, "dependsOn": [ "[concat('Microsoft.Sql/servers/', variables('dbServerName'))]" ] } ] } ], "outputs": { } }

Then try to delete with "empty" template.

You'll get infinite loop of DB Deletion "Started .. Accepted .. Failed .. Started .. Accepted .. Failed .. Started ..."

1
Dmitry - this sounds like a bug - can you reproduce this or by chance do you have a correlationId from a failed deployment?bmoore-msft
I added an example. I am not sure if I can share correlation IDs to public.Dmitry Andrievsky
I ran a few deployments today using the sample and all seemed to go fine... correlationIds aren't secret and only visible if you own those events. But if you can email some send to bmoore at microsoftbmoore-msft

1 Answers

2
votes

First and most obvious way of doing this: delete the resource group. recreating it takes 5 seconds, an empty resource group isnt worth much, you can script tags\permissions to reapply them.

Another way could be this:

Get-AzureRmResource | ? ResourceGroupName -eq your_resource_group_name | Remove-AzureRmResource -WhatIf

You can remove -WhatIf when you are confident this only targets the resources you want. You can also use -AsJob to speed deletion up