Azure not deleting old deployment resources automatically

Janne Kujanpää 206 Reputation points
2023-01-09T19:54:27.277+00:00

I just hit limit of the 800 deployment resources on brand new subscription. I checked tutorial(1) and it really did not at all.

Running az deployment sub create --template-file template/main.bicep --parameters template/main.parameters.json --name main fails with:

{"code": "MultipleErrorsOccurred", "message": "Multiple error occurred: Conflict,Conflict,Conflict,Conflict,Conflict,Conflict. Please see details."}  
  
Inner Errors:   
{"code": "DeploymentQuotaExceeded", "message": "Creating the deployment 'QualysPolicyAssignment1673289101' would exceed the quota of '800'. The current deployment count is '800'. Please delete some deployments before creating a new one, or see https://aka.ms/800LimitFix for information on managing deployment limits."}  
  
Inner Errors:   
{"code": "DeploymentQuotaExceeded", "message": "Creating the deployment 'AMADefaultLaw1673289101' would exceed the quota of '800'. The current deployment count is '800'. Please delete some deployments before creating a new one, or see https://aka.ms/800LimitFix for information on managing deployment limits."}  
...  

I have not opted out from the automatic deployment deletion: az feature show --namespace Microsoft.Resources --name DisableDeploymentGrooming

{  
  "id": "/subscriptions/50e9bd86-fa9c-422f-be15-4a37557fbdb8/providers/Microsoft.Features/providers/Microsoft.Resources/features/DisableDeploymentGrooming",  
  "name": "Microsoft.Resources/DisableDeploymentGrooming",  
  "properties": {  
    "state": "NotRegistered"  
  },  
  "type": "Microsoft.Features/providers/features"  
}  

Also no resource locks are present: az lock list

[]  

Some pruning probably happened az deployment sub list --query "[].name" --output tsv | wc -l

600  

but still deployments fails with

{"code": "DeploymentQuotaExceeded", "message": "Creating the deployment 'AksDefenderExtensionPolicyAssignment1673290410' would exceed the quota of '800'. The current deployment count is '802'. Please delete some deployments before creating a new one, or see https://aka.ms/800LimitFix for information on managing deployment limits."}  

I wonder what would be the next steps with the issue?

Ps. I tried to ask correct tag or support ticket service type from @AzureSupport but did not get any good answers. Please let me know about more suitable tags.

(1) https://video2.skills-academy.com/en-gb/azure/azure-resource-manager/templates/deployment-history-deletions?tabs=azure-cli

Azure Cost Management
Azure Cost Management
A Microsoft offering that enables tracking of cloud usage and expenditures for Azure and other cloud providers.
2,285 questions
Azure FastTrack
Azure FastTrack
Azure: A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.FastTrack: This tag is no longer in use. Please use 'Azure Startups' instead.
75 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Manu Philip 17,186 Reputation points MVP
    2023-01-09T20:04:48.75+00:00

    You may use some automated way of deleting the history. An example PowerShell script is given below: change the days value as well as the Resource Group Name conveniently

    $deployments = Get-AzResourceGroupDeployment -ResourceGroupName <RGName> | Where-Object Timestamp -lt ((Get-Date).AddDays(-60))  
      
    foreach ($deployment in $deployments) {  
      Remove-AzResourceGroupDeployment -ResourceGroupName <RGName> -Name $deployment.DeploymentName  
    }  
    

    --please don't forget to upvote and Accept as answer if the reply is helpful--

    0 comments No comments

  2. Luke Murray 10,636 Reputation points MVP
    2023-02-02T23:59:40.3566667+00:00

    Hi, all.

    This question inspired me to write a script and the blog post here: https://luke.geek.nz/azure/azure-deployment-cleanup-with-azure-devops/

    Hopefully, it's of use.

    0 comments No comments