@@ -836,7 +836,7 @@ func (p *BicepProvider) Destroy(
836836 if len (groupedResources ) == 0 {
837837 p .console .StopSpinner (ctx , "" , input .StepDone )
838838 // Call deployment.Delete to void the state even though there are no resources to delete
839- if err := p .destroyDeploymentWithoutConfirmation (ctx , deploymentToDelete ); err != nil {
839+ if err := p .destroyDeployment (ctx , deploymentToDelete ); err != nil {
840840 return nil , fmt .Errorf ("voiding deployment state: %w" , err )
841841 }
842842 } else {
@@ -866,13 +866,15 @@ func (p *BicepProvider) Destroy(
866866 }
867867
868868 p .console .StopSpinner (ctx , "" , input .StepDone )
869- if err := p .destroyDeploymentWithConfirmation (
870- ctx ,
871- options ,
872- deploymentToDelete ,
873- groupedResources ,
874- len (resourcesToDelete ),
875- ); err != nil {
869+
870+ // Prompt for confirmation before deleting resources
871+ if err := p .promptDeletion (ctx , options , groupedResources , len (resourcesToDelete )); err != nil {
872+ return nil , err
873+ }
874+
875+ p .console .Message (ctx , output .WithGrayFormat ("Deleting your resources can take some time.\n " ))
876+
877+ if err := p .destroyDeployment (ctx , deploymentToDelete ); err != nil {
876878 return nil , fmt .Errorf ("deleting resource groups: %w" , err )
877879 }
878880
@@ -1070,68 +1072,43 @@ func (p *BicepProvider) generateResourcesToDelete(groupedResources map[string][]
10701072 return append (lines , "\n " )
10711073}
10721074
1073- // Deletes the azure resources within the deployment
1074- func (p * BicepProvider ) destroyDeploymentWithConfirmation (
1075+ // promptDeletion prompts the user for confirmation before deleting resources.
1076+ // Returns nil if the user confirms, or an error if they deny or an error occurs.
1077+ func (p * BicepProvider ) promptDeletion (
10751078 ctx context.Context ,
10761079 options provisioning.DestroyOptions ,
1077- deployment infra.Deployment ,
10781080 groupedResources map [string ][]* azapi.Resource ,
10791081 resourceCount int ,
10801082) error {
1081- if ! options .Force () {
1082- p .console .MessageUxItem (ctx , & ux.MultilineMessage {
1083- Lines : p .generateResourcesToDelete (groupedResources )},
1084- )
1085- confirmDestroy , err := p .console .Confirm (ctx , input.ConsoleOptions {
1086- Message : fmt .Sprintf (
1087- "Total resources to %s: %d, are you sure you want to continue?" ,
1088- output .WithErrorFormat ("delete" ),
1089- resourceCount ,
1090- ),
1091- DefaultValue : false ,
1092- })
1093-
1094- if err != nil {
1095- return fmt .Errorf ("prompting for delete confirmation: %w" , err )
1096- }
1097-
1098- if ! confirmDestroy {
1099- return errors .New ("user denied delete confirmation" )
1100- }
1083+ if options .Force () {
1084+ return nil
11011085 }
11021086
1103- p .console .Message (ctx , output .WithGrayFormat ("Deleting your resources can take some time.\n " ))
1104-
1105- err := async .RunWithProgressE (func (progressMessage azapi.DeleteDeploymentProgress ) {
1106- switch progressMessage .State {
1107- case azapi .DeleteResourceStateInProgress :
1108- p .console .ShowSpinner (ctx , progressMessage .Message , input .Step )
1109- case azapi .DeleteResourceStateSucceeded :
1110- p .console .StopSpinner (ctx , progressMessage .Message , input .StepDone )
1111- case azapi .DeleteResourceStateFailed :
1112- p .console .StopSpinner (ctx , progressMessage .Message , input .StepFailed )
1113- }
1114- }, func (progress * async.Progress [azapi.DeleteDeploymentProgress ]) error {
1115- optionsMap , err := convert .ToMap (p .options )
1116- if err != nil {
1117- return err
1118- }
1119-
1120- return deployment .Delete (ctx , optionsMap , progress )
1087+ p .console .MessageUxItem (ctx , & ux.MultilineMessage {
1088+ Lines : p .generateResourcesToDelete (groupedResources )},
1089+ )
1090+ confirmDestroy , err := p .console .Confirm (ctx , input.ConsoleOptions {
1091+ Message : fmt .Sprintf (
1092+ "Total resources to %s: %d, are you sure you want to continue?" ,
1093+ output .WithErrorFormat ("delete" ),
1094+ resourceCount ,
1095+ ),
1096+ DefaultValue : false ,
11211097 })
11221098
11231099 if err != nil {
1124- return err
1100+ return fmt . Errorf ( "prompting for delete confirmation: %w" , err )
11251101 }
11261102
1127- p .console .Message (ctx , "" )
1103+ if ! confirmDestroy {
1104+ return errors .New ("user denied delete confirmation" )
1105+ }
11281106
11291107 return nil
11301108}
11311109
1132- // destroyDeploymentWithoutConfirmation deletes the deployment without prompting for confirmation.
1133- // This is used when there are no resources to delete but we still need to void the deployment state.
1134- func (p * BicepProvider ) destroyDeploymentWithoutConfirmation (
1110+ // destroyDeployment deletes the azure resources within the deployment and voids the deployment state.
1111+ func (p * BicepProvider ) destroyDeployment (
11351112 ctx context.Context ,
11361113 deployment infra.Deployment ,
11371114) error {
0 commit comments