title: AZURE Resource Manager: Clean up resource group
body: <p><strong>TL;DR:</strong> </p>
  
  <blockquote>
    <p>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?</p>
  </blockquote>
  
  <p>Delete resource group is not an option (access rights: Contributor, not owner)</p>
  
  <p><strong>Details:</strong></p>
  
  <p>I am trying to completely clean up resource group in AZURE.</p>
  
  <p>Delete resource group is not an option (access rights: Contributor, not owner)</p>
  
  <p>Most elegant and obvious way to do this (also described in some articles) is to perform Complete deployment with "empty" deployment template:</p>
  
  <p><code>New-AzureRmResourceGroupDeployment -Mode Complete -ResourceGroupName RG_NAME -TemplateFile .\empty.json</code></p>
  
  <p>with the following empty.json:</p>
  
  <p><code>{
      "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
      "contentVersion": "2018-02-15",
      "parameters": {},
      "variables": {},
      "resources": [],
      "outputs": {}
  }
  </code></p>
  
  <p>But...
  This works <em>sometimes</em>. Even not <strong>most</strong> of the time.</p>
  
  <p>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 </p>
  
  <blockquote>
    <p>"Delete SQL Server Started" ... "Accepted" ... "Failed" ... "Started"
    ... "Accepted" ... "Failed" ... ...</p>
  </blockquote>
  
  <p>You got the idea.</p>
  
  <p>Other times it works fine.</p>
  
  <p>So, the question is: <strong>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?</strong></p>
  
  <p><strong>Example that seems to be repeatable</strong></p>
  
  <ol>
  <li><p>Try to deploy SQL server with the following template (it will fail with password complexity validation)</p>
  
  <p>{
      "$schema": "<a href="http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#" rel="nofollow noreferrer">http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#</a>",
      "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": {
      }
  }</p></li>
  </ol>
  
  <p>Then try to delete with "empty" template.</p>
  
  <p>You'll get infinite loop of DB Deletion "Started .. Accepted .. Failed .. Started .. Accepted .. Failed .. Started ..."</p>