@@ -109,14 +109,21 @@ func (ac *AzureClient) CreateOrUpdateAsync(ctx context.Context, spec azure.Resou
109
109
// request to Azure and if accepted without error, the func will return a Poller which can be used to track the ongoing
110
110
// progress of the operation.
111
111
func (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" )
113
113
defer done ()
114
114
115
115
forceDelete := ptr .To (true )
116
116
opts := & armcompute.VirtualMachinesClientBeginDeleteOptions {ResumeToken : resumeToken , ForceDeletion : forceDelete }
117
117
poller , err = ac .virtualmachines .BeginDelete (ctx , spec .ResourceGroupName (), spec .ResourceName (), opts )
118
118
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
+ }
120
127
}
121
128
122
129
ctx , cancel := context .WithTimeout (ctx , ac .apiCallTimeout )
0 commit comments