@@ -109,14 +109,21 @@ func (ac *AzureClient) CreateOrUpdateAsync(ctx context.Context, spec azure.Resou
109109// request to Azure and if accepted without error, the func will return a Poller which can be used to track the ongoing 
110110// progress of the operation. 
111111func  (ac  * AzureClient ) DeleteAsync (ctx  context.Context , spec  azure.ResourceSpecGetter , resumeToken  string ) (poller  * runtime.Poller [armcompute.VirtualMachinesClientDeleteResponse ], err  error ) {
112- 	ctx , _ , done  :=  tele .StartSpanWithLogger (ctx , "virtualmachines.AzureClient.Delete" )
112+ 	ctx , log , done  :=  tele .StartSpanWithLogger (ctx , "virtualmachines.AzureClient.Delete" )
113113	defer  done ()
114114
115115	forceDelete  :=  ptr .To (true )
116116	opts  :=  & armcompute.VirtualMachinesClientBeginDeleteOptions {ResumeToken : resumeToken , ForceDeletion : forceDelete }
117117	poller , err  =  ac .virtualmachines .BeginDelete (ctx , spec .ResourceGroupName (), spec .ResourceName (), opts )
118118	if  err  !=  nil  {
119- 		return  nil , err 
119+ 		if  azure .BadRequest (err ) {
120+ 			log .Info ("Failed to Begin VM Delete with Force Deletion, retrying without the force flag" )
121+ 			opts .ForceDeletion  =  ptr .To (false )
122+ 			poller , err  =  ac .virtualmachines .BeginDelete (ctx , spec .ResourceGroupName (), spec .ResourceName (), opts )
123+ 		}
124+ 		if  err  !=  nil  {
125+ 			return  nil , err 
126+ 		}
120127	}
121128
122129	ctx , cancel  :=  context .WithTimeout (ctx , ac .apiCallTimeout )
0 commit comments