Merge pull request #8430 from hashicorp/fix_8359

Fix request retry mechanism  to launch aws instance
pull/8447/head
Megan Marsh 7 years ago committed by GitHub
commit de9f391a1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,11 +3,11 @@ package common
import (
"context"
"fmt"
"github.com/aws/aws-sdk-go/aws"
"log"
"time"
"encoding/json"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/iam"
"github.com/hashicorp/packer/common/uuid"
"github.com/hashicorp/packer/helper/multistep"
@ -138,8 +138,6 @@ func (s *StepIamInstanceProfile) Run(ctx context.Context, state multistep.StateB
s.roleIsAttached = true
state.Put("iamInstanceProfile", aws.StringValue(profileResp.InstanceProfile.InstanceProfileName))
time.Sleep(5 * time.Second)
}
return multistep.ActionContinue

@ -194,9 +194,20 @@ func (s *StepRunSourceInstance) Run(ctx context.Context, state multistep.StateBa
runOpts.InstanceInitiatedShutdownBehavior = &s.InstanceInitiatedShutdownBehavior
}
runReq, runResp := ec2conn.RunInstancesRequest(runOpts)
runReq.RetryCount = 11
err = runReq.Send()
var runResp *ec2.Reservation
err = retry.Config{
Tries: 11,
ShouldRetry: func(err error) bool {
if isAWSErr(err, "InvalidParameterValue", "iamInstanceProfile") {
return true
}
return false
},
RetryDelay: (&retry.Backoff{InitialBackoff: 200 * time.Millisecond, MaxBackoff: 30 * time.Second, Multiplier: 2}).Linear,
}.Run(ctx, func(ctx context.Context) error {
runResp, err = ec2conn.RunInstances(runOpts)
return err
})
if isAWSErr(err, "VPCIdNotSpecified", "No default VPC for this user") && subnetId == "" {
err := fmt.Errorf("Error launching source instance: a valid Subnet Id was not specified")

Loading…
Cancel
Save