Reputation: 1910
I am deploying my bicep template and it errors-out with the message:
Unable to edit or replace deployment '2024-12-12T112858Z-deployment-name': previous deployment from '12/12/2024 11:32:11 AM' is still active
But this is not the case. There are no running deployments. I checked the gui in the portal and also confirmed with
$d = az deployment sub list | convertfrom-json
($d | select properties).properties.provisioningState | select $_ -Unique
which returns only
Succeeded
Failed
I basically cannot deploy anymore. What can I do to debug this? This states that deployment names must be unique, but they are in my case, that's why I included a timestamp as prefix.
Upvotes: 0
Views: 167
Reputation: 7820
Bicep deployment fails because there is supposedly one still running, but isnt
If you're still getting the message that a deployment is in an active status, even when using a timeframe, it might be at a different scope (such as the resource group or subscription level) or associated with a different name. You can check for active deployments at the subscription, resource group, and management group levels.
Verify active deployments across all scopes using below cmdlet
az deployment sub list --query "[].{Name:name, State:properties.provisioningState}" -o table
az deployment group list --resource-group <resource-group-name> --query "[].{Name:name, State:properties.provisioningState}" -o table
az deployment mg list --management-group-id --query "[].{Name:name, State:properties.provisioningState}" -o table
**AND**
Check all scopes for any deployments in a running state so that if any deployment is running, you can cancel it and deploy again with UUID.
--query "[?properties.provisioningState=='Running']"
Cancel the deployment and then execute it again with a UUID
az deployment sub cancel --name <deployment-name>
az deployment group cancel --resource-group <resource-group-name> --name <deployment-name>
az deployment mg cancel --management-group-id --name
Even though you're adding a timestamp to the deployment name, make sure it is formatted correctly and includes a unique identifier for each deployment.
az deployment sub create --name "deployment-$(date +%Y-%m-%dT%H%M%S)" --location "eastus" --template-file ./venkat.bicep
In my case, when I add the time frame for the deployment, the deployment is created with the same name both times.
1st Deployment
2nd Deployment
To avoid duplicate names, you can use a UUID for a unique deployment name for each deployment.
az deployment sub create --name "deployment-$(uuidgen)" --location "eastus" --template-file ./venkat.bicep
After running the command, the deployment names are different each time.
1st deployment name
2nd deployment name
Upvotes: 0