@@ -412,6 +412,9 @@ func (s *StepRunSpotInstance) Run(ctx context.Context, state multistep.StateBag)
412
412
// we can wait on those operations, this can be removed.
413
413
return true
414
414
}
415
+ if err .Error () == "InsufficientInstanceCapacity" {
416
+ return true
417
+ }
415
418
return false
416
419
},
417
420
RetryDelay : (& retry.Backoff {InitialBackoff : 500 * time .Millisecond , MaxBackoff : 30 * time .Second , Multiplier : 2 }).Linear ,
@@ -432,6 +435,12 @@ func (s *StepRunSpotInstance) Run(ctx context.Context, state multistep.StateBag)
432
435
if err != nil {
433
436
log .Printf ("create request failed %v" , err )
434
437
}
438
+ // We can end up unavailable Spot capacity, we keep retrying
439
+ for _ , err := range createOutput .Errors {
440
+ if err .ErrorCode != nil && * err .ErrorCode == "InsufficientInstanceCapacity" {
441
+ return fmt .Errorf (* err .ErrorCode )
442
+ }
443
+ }
435
444
return err
436
445
})
437
446
@@ -512,10 +521,7 @@ func (s *StepRunSpotInstance) Run(ctx context.Context, state multistep.StateBag)
512
521
513
522
// Retry creating tags for about 2.5 minutes
514
523
err = retry.Config {Tries : 11 , ShouldRetry : func (err error ) bool {
515
- if awserrors .Matches (err , "InvalidInstanceID.NotFound" , "" ) {
516
- return true
517
- }
518
- return false
524
+ return awserrors .Matches (err , "InvalidInstanceID.NotFound" , "" )
519
525
},
520
526
RetryDelay : (& retry.Backoff {InitialBackoff : 200 * time .Millisecond , MaxBackoff : 30 * time .Second , Multiplier : 2 }).Linear ,
521
527
}.Run (ctx , func (ctx context.Context ) error {
0 commit comments