predown hook is called before confirmation prompt
- [X] Make sure you've installed the latest version using instructions in the wiki
Output from azd version
Run azd version and copy and paste the output here:
~ azd version
azd version 1.6.1 (commit eba2c978b5443fdb002c95add4011d9e63c2e76f)
Describe the bug
We have a predown hook that removes budgets and diagnostic settings - things that are not handled by the normal "down" procedure and need to be sequenced. However, the predown hook is run prior to the confirmation dialog, meaning that the user is left with a broken deployment if they answer "no" to the azd down prompt.
~ azd down
Azure hub group name not found in environment variables. No cleanup needed. Exiting...
Removing budgets for resource group rg-adhal-0306-02-dev-westus3-application
Removing rg-adhal-0306-02-dev-westus3-application::budget-adhal-0306-02-dev-westus3
Deleting all resources and deployed code on Azure (azd down)
Local application code is not deleted when running 'azd down'.
Resource group(s) to be deleted:
• rg-adhal-0306-02-dev-westus3-application: https://portal.azure.com/#@/resource/subscriptions/6ad866ae-f77e-4d58-8f02-a00a75a0e21b/resourceGroups/rg-adhal-0306-02-dev-westus3-application/overview
? Total resources to delete: 16, are you sure you want to continue? Yes
Deleting your resources can take some time.re you want to continue? (y/N) y
(✓) Done: Deleting resource group: rg-adhal-0306-02-dev-westus3-application
Note that the output of our predown script is executed before the question about continuing. Since we cannot delete the budgets and diagnostic settings after the resource groups have been removed, this is a problem that leaves dangling resources.
To Reproduce Create a predown script with some output to show off the sequencing.
Expected behavior I expect to be able to configure a hook that is run only after the confirmation that we want to do something. This can be a new hook or by moving the existing predown hook.
Environment Information on your environment: * Language name and version - C# * IDE and version : VS Code (latest insiders)
Additional context Internal (to Microsoft) repro is available if you prefer.
@wbreza added to Germanium bucket. Feel free to pull it into respective milestones.
This is by design. Any pre hook scripts run before any of the associated commands.
Figured it would be by design - which means the question is "Can we please have a hook that is "post-confirmation-and-predown"? Not sure what you would call it - "preresourcedeletion" maybe?
@adrianhall - I'm not an expert on the budgets / diagnostic settings you are using - but is there a way these can be represented in your bicep so that they are cleaned up correctly?
The call to azd down is basically the initial acceptance that you want to remove the resources provisioned by azd. The confirmation is to just confirm that there were any manually added resources that should not be deleted.
Maybe the real question is do you have a use case where a user runs azd down but then ops out of confirming the deletion?
Unfortunately, no. They are already represented in the bicep for creation, but there is an ordering issue with deletions. Budgets and diagnostic settings are the most common settings here. Another one is in network isolated environments where you need to depeer a pair of vnets prior to deleting (otherwise there is an unresolvable dependency chain). The point being - there are multiple reasons why you need to script things prior to running the azd down portion.
For your other question: If you don't have a use case where a user runs azd down and then opts out, why do you give the user the option to opt out confirming the deletion? If you have the opt-out available, then the templates should support opting out.
This issue has been automatically marked as stale because it has not had any activity in the last year!!, and it will be closed in 30 days if no further activity occurs.
If you think this is a mistake, please comment on this issue to keep it open.