You may, or may not, be aware that there is a limit on the amount of Deployments you can make to a Resource Group in Azure. This limit defaults at 800. This means that once you hit the limit you can no longer make any further Resource Group Deployments.

When the case, there are two options available:

  • raise a support ticket with Microsoft asking for the limit to be increased – bare in mind that you will likely hit the increased limit if you have already reached the default limit. In which case,
  • you can delete a number of the Resource Group Deployments. Be assured, this does not delete any resources, but you will want to delete the oldest as each deployment contains the details of the ARM resources and parameters for each deployment.

Particularly where you may be working on large, multi-disciplinary teams, you may wish to opt for a mechanism that clears-down the Resource Group Deployments on a routine basis.

From personal experience, this was a matter of running a PowerShell script once a day via Azure DevOps. If you opt for the same approach, using Azure DevOps, you’ll be aware that you can run scripts on a routine basis from either a hosted or a self-hosted Agent. Given that deleting a Resource Group Deployment takes a lengthy period of time to complete, you may want to reconsider the use of a hosted agent which may consume valuable minutes on your plan.

If you find yourself needing to clear-down Deployments on a regular basis, I have prepared a script which you can use:

################################################################################################################################################################
### RESOURCE GROUP Cleardown:
### Script is used to clear down resource group deployments.  When the number of deployments reaches 800 no further deployments can be made to a resource group.
### This script was initially designed to display the number of Resource Group Deployments of all Resource Groups, and delete those Deployments where the 
### total number exceeded the safelimit
################################################################################################################################################################ 

### Only items in this section should be changed ###
$safelimit = 625 # clear down takes place when the number of deployments are great than or equal to this
$cleardownlevel = 600 # the level at which deployments will be cleared-down to
$SEARCHCRITERIA = '*' # wildcard naming for Resource Group can be used - applies to deletion step only

### Note: the commented section, lines 31-35, should remain in place and the script run.  When satisfied that figures are correct, remove comments and proceed to 
### remove the Resource Group Deployments.
### This script comes with no warranty.
####################################################

Get-AzureRmResourceGroup |  ForEach-Object {
    $deployments = Get-AzureRmResourceGroupDeployment -ResourceGroupName $_.ResourceGroupName #get the deployments for the resource group
    Write-Host "`n"$_.ResourceGroupName": "$deployments.Count
    
	# only remove deployments when they are above the agreed safe limit and are associated with the your solution
    if ($deployments.Count -ge $safelimit -and $_.ResourceGroupName -like $SEARCHCRITERIA) { 
        Write-Host "  >>"$_.ResourceGroupName"deployments to be cleared." -ForegroundColor Yellow

        $sortedDeployments = $deployments | Sort-Object TimeStamp #sort in order to remove the oldest
        $count = $deployments.Count
        write-host "  >> count: $count"
        
        write-host "  >> cleardownlevel: $cleardownlevel"
        <# for ($i=0; $i -lt ($count - $cleardownlevel)) {
           write-host "Removing deployment "$sortedDeployments[$i].DeploymentName
           Remove-AzureRmResourceGroupDeployment -ResourceGroupName $_.ResourceGroupName -Name $sortedDeployments[$i].DeploymentName #remove the deployment
           $i++
        } #>
          # << uncomment this section when you are sure you're ready to delete the resource group deployments - it's recommended you run before uncommenting 
    }
} 

You can also access this script from my GitHub Repository: