none
Azure resource deletion taking ages RRS feed

  • Question

  • I am currently developing a Powershell script to allow us to create an instance of our application and this involves running the script many times as part of the development and debugging process.  Up until today the process of deleting the resources  contained within a resource group was just about bearable however today it is taking over 30 minutes to delete a resource group with 8 services contained within it.

    Not only that it reported the resource group as deleted but it transpired that it hadn't deleted everything, there were still resources left behind, I haven't seen this issue up until today.

    This deletion process is being initiated through the Portal.

    Is there a better way to develop these scripts with a more responsive instance of the Azure platform, like a locally installed version??

     
    • Edited by Andy HB Friday, August 23, 2019 9:26 AM
    Friday, August 23, 2019 9:25 AM

All replies

  • Hi Andy,

    I don't think you have to go for locally installed version but for testing purpose you may first test the script in locally installed version and then go for next version of it to fit in Cloud setup so that maintenance is easy.

    I would suggest you to add '-Verbose' common parameter to your PowerShell cmdlet and see if it provides information regarding at what step (i.e., to delete which resource) it is taking more time.

    If possible, share the PowerShell script that you are using to delete so that we would have more context to understand the request.


    If you are deleting resource group then you may use PowerShell cmdlet Remove-AzResourceGroup

    Get-AzResourceGroup -Name "<ResourceGroupName>" | Remove-AzResourceGroup -Verbose -Force


    If you are deleting all resources in a resource group but not deleting resource group then use PowerShell cmdlet New-AzResourceGroupDeployment to deploy an empty template with no resources in an existing resource group in 'Complete' mode.

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

    Save above content in a JSON file say xxxxxxx.json. And then run below command.

    New-AzureRmResourceGroupDeployment -ResourceGroupName "<ResourceGroupName>" -Mode Complete -TemplateFile .\xxxxxxx.json -Force -Verbose


    In your case as it reported the resource group as deleted but actually there were still resources left behind so to overcome such issues, I would develop PowerShell script with blocks / functions like 
    1) Pre-validation -> Check whether resources and it's dependent resources are existing or not.
    2) Action -> Delete the existing resources (first it's dependent resources and then the actual resource).
    3) Post-validation -> Check whether resources and it's dependent resources are delete successfully or not. If answer is 'not deleted' then call above 'Pre-validation' only one extra time to see if second iteration cleans the things up.

    Hope this helps!
    Monday, August 26, 2019 6:06 AM
    Moderator