Unable to delete subscription deployment stack: Deleting the deployment stack fails both from the Azure portal and using Azure CLI

Nicolas Lykke Iversen 0 Reputation points
2025-01-27T08:58:24.3266667+00:00

I have created a deployment stack at the subscription level. Deletion of the deployment stack failed several weeks ago, and Azure haven't cleaned it up yet. I have tried to delete the deployment stack both using the Azure portal and Azure CLI, but both fails. How can I force the deletion of the deployment stack? None of the deployed resources exist anymore
User's image

Error:

{
  "code": "DeploymentStackDeleteResourcesFailed",
  "message": "One or more resources could not be deleted. Correlation id: 'ab2a2eb3-6c14-4f7d-81de-5607775bbda6'.",
  "details": [
    {
      "code": "DeploymentStackDeleteResourcesFailed",
      "message": "An error occurred while deleting resources. These resources are still present in the stack but can be deleted manually. Please see the FailedResources property for specific error information. Deletion failures that are known limitations are documented here: https://aka.ms/DeploymentStacksKnownLimitations"
    }
  ]
}

Deployment:

/subscriptions/f523cecd-3a1f-479e-bdec-3ac5e41d12c5/providers/Microsoft.Resources/deployments/IAM-AssetGovernance-PR-54-25010709f8i9k
Azure Cost Management
Azure Cost Management
A Microsoft offering that enables tracking of cloud usage and expenditures for Azure and other cloud providers.
2,978 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Madugula Jahnavi 0 Reputation points Microsoft Vendor
    2025-01-29T10:24:33.07+00:00

    Hi @Nicolas Lykke Iversen

    Thank you for reaching out to Microsoft Q&A!

    Firstly, when you are trying to delete a deployment stack created at subscription scope level delete the resource groups or resources existed in it through portal or any other script. To allow the delete resource operations in the stack, make sure that the DenySettingsMode is set to None and delete it accordingly.

    I deployed a deployment stack in the Azure portal, added a few resources to it, and attempted the delete operation using the "Delete stack" button and click on Detach resources option under "Update behavior". It worked as expected.

    User's image

    And to delete the deployment stack at subscription level, you need to use az stack sub delete AZCLI command as detailed in below MS Doc.
    Link: https://learn.microsoft.com/en-us/cli/azure/stack/sub?view=azure-cli-latest#az-stack-sub-delete

    If still the issue persists and to apply force delete on the deployment stack deletion operation, there is a relevant Az PowerShell command called Remove-AzSubscriptionDeploymentStack with stack name and force arguments.

    MS Doc: https://learn.microsoft.com/en-us/powershell/module/az.resources/remove-azsubscriptiondeploymentstack?view=azps-13.0.0#examples

    I have executed it in my environment and was able to perform it successfully without any conflict.

    newimage

    Note: I can see that the error message is likely "DeploymentStackDeleteResourcesFailed", it exactly means that Azure could not be able to remove some resources on deployment stacks. As suggested in your error message, go to the corresponding resource groups where the resources have been deployed and delete them manually.

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.