@@ -412,6 +412,9 @@ func (s *StepRunSpotInstance) Run(ctx context.Context, state multistep.StateBag)
412412 // we can wait on those operations, this can be removed.
413413 return true
414414 }
415+ if err .Error () == "InsufficientInstanceCapacity" {
416+ return true
417+ }
415418 return false
416419 },
417420 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)
432435 if err != nil {
433436 log .Printf ("create request failed %v" , err )
434437 }
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+ }
435444 return err
436445 })
437446
@@ -512,10 +521,7 @@ func (s *StepRunSpotInstance) Run(ctx context.Context, state multistep.StateBag)
512521
513522 // Retry creating tags for about 2.5 minutes
514523 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" , "" )
519525 },
520526 RetryDelay : (& retry.Backoff {InitialBackoff : 200 * time .Millisecond , MaxBackoff : 30 * time .Second , Multiplier : 2 }).Linear ,
521527 }.Run (ctx , func (ctx context.Context ) error {
0 commit comments