@@ -413,6 +413,9 @@ func (s *StepRunSpotInstance) Run(ctx context.Context, state multistep.StateBag)
413413 // we can wait on those operations, this can be removed.
414414 return true
415415 }
416+ if err .Error () == "InsufficientInstanceCapacity" {
417+ return true
418+ }
416419 return false
417420 },
418421 RetryDelay : (& retry.Backoff {InitialBackoff : 500 * time .Millisecond , MaxBackoff : 30 * time .Second , Multiplier : 2 }).Linear ,
@@ -433,6 +436,12 @@ func (s *StepRunSpotInstance) Run(ctx context.Context, state multistep.StateBag)
433436 if err != nil {
434437 log .Printf ("create request failed %v" , err )
435438 }
439+ // We can end up unavailable Spot capacity, we keep retrying
440+ for _ , err := range createOutput .Errors {
441+ if err .ErrorCode != nil && * err .ErrorCode == "InsufficientInstanceCapacity" {
442+ return fmt .Errorf (* err .ErrorCode )
443+ }
444+ }
436445 return err
437446 })
438447
@@ -513,10 +522,7 @@ func (s *StepRunSpotInstance) Run(ctx context.Context, state multistep.StateBag)
513522
514523 // Retry creating tags for about 2.5 minutes
515524 err = retry.Config {Tries : 11 , ShouldRetry : func (err error ) bool {
516- if awserrors .Matches (err , "InvalidInstanceID.NotFound" , "" ) {
517- return true
518- }
519- return false
525+ return awserrors .Matches (err , "InvalidInstanceID.NotFound" , "" )
520526 },
521527 RetryDelay : (& retry.Backoff {InitialBackoff : 200 * time .Millisecond , MaxBackoff : 30 * time .Second , Multiplier : 2 }).Linear ,
522528 }.Run (ctx , func (ctx context.Context ) error {
0 commit comments