Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 20, 2025

Fix azd down to void deployment state even when resources are already deleted

This PR addresses issue #6207 where azd down fails to void the deployment state when resource groups have been manually deleted.

Plan:

  • Understand the issue and codebase
  • Refactor DeleteSubscriptionDeployment to extract state voiding logic
  • Update DeleteSubscriptionDeployment to void state even when no resources exist
  • Update bicep provider to handle zero resources case gracefully
  • Add detailed comments explaining the behavior
  • Refactor to remove code duplication (PR feedback)
  • Run linting and formatting
  • Run comprehensive tests (all pass)
  • Run CodeQL security scan (no vulnerabilities)
  • Ready for code review

Changes Made:

standard_deployments.go

  • Extracted voidSubscriptionDeploymentState method from DeleteSubscriptionDeployment
  • This separates the concern of voiding state from resource deletion
  • The extracted method creates an empty ARM deployment to clear the state
  • Now called unconditionally after attempting to delete resource groups

bicep_provider.go

  • Modified Destroy method to handle the case when no resources are found
  • Refactored to remove code duplication:
    • promptDeletion - handles user confirmation prompt
    • destroyDeployment - single method for the actual deletion logic (no duplication)
  • When no resources found, voids the state without prompting
  • When resources exist, prompts for confirmation then deletes

Test Results:

  • ✅ All existing tests pass
  • ✅ Build succeeds
  • ✅ Code formatting and linting clean

Scope:
This change only applies to:

  • Bicep deployments
  • Standard deployments (not deployment stacks)
  • Subscription-scoped deployments
Original prompt

See #6207
Investigate azd down implementation. Look how azd down voids the deployment state at some point, after deleting all resource groups, by creating a new empty deployment which becomes the last succesful deployment in the deployment history for the combination of the environment-name and rg.
However, if the user has manually delete all rgs and azd down did found any, it just return an error mentioning that there are no resources.
Make azd to void the deployment state anyway and create the empty deployment.
NOTE: This only applies to bicep deployments and to standar_deployments.
The code to void the state is currently inside the code to DeleteSubscriptionDeployment in #file:standard_deployments.go:459-488
This mens that we might need some refactory to support voiding the state with an empty deployment without actually calling the DeleteSubscriptionDeployment().
Or It could also work to just try to delete the resource groups discovered from the deployment and if the rg is not found, just log it and continue - assuming it is already manually deleted. THis way the code to void the state will be eventually triggered even if the resource groups are not found


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits November 20, 2025 05:38
…eted

Extract state voiding logic into separate method and ensure it runs even when no resources are found. This allows azd down to properly clean deployment state when resources have been manually deleted.

Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com>
Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com>
Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor azd down to void deployment state on resource deletion Fix azd down to void deployment state when resources are manually deleted Nov 20, 2025
Copilot AI requested a review from vhvb1989 November 20, 2025 05:51
Copilot finished work on behalf of vhvb1989 November 20, 2025 05:51
@vhvb1989 vhvb1989 marked this pull request as ready for review November 20, 2025 21:56

// destroyDeploymentWithoutConfirmation deletes the deployment without prompting for confirmation.
// This is used when there are no resources to delete but we still need to void the deployment state.
func (p *BicepProvider) destroyDeploymentWithoutConfirmation(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation of the delete logic is duplicated across destroyDeploymentWithConfirmation and destroyDeploymentWithoutConfirmation. Consider refactoring slightly to remove the duplication.

I would recommend having a single destroyDeployment, and factor out the confirmation prompt logic as promptDeletion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored to have a single destroyDeployment method and a separate promptDeletion method to handle the confirmation prompt. This removes the duplication. See commit 028bfc0.

…ve duplication

Co-authored-by: JeffreyCA <9157833+JeffreyCA@users.noreply.github.com>
Copilot finished work on behalf of JeffreyCA November 26, 2025 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants