Skip to content

Commit

Permalink
Merge pull request #9078 from terraform-providers/rfd-retry-spot
Browse files Browse the repository at this point in the history
Retries after timeouts on spot resources
  • Loading branch information
ryndaniels authored Jun 21, 2019
2 parents 798aaf3 + df302d6 commit f64f57a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
15 changes: 7 additions & 8 deletions aws/resource_aws_spot_fleet_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,22 +703,21 @@ func resourceAwsSpotFleetRequestCreate(d *schema.ResourceData, meta interface{})
// take effect immediately, resulting in an InvalidSpotFleetRequestConfig error
var resp *ec2.RequestSpotFleetOutput
err = resource.Retry(10*time.Minute, func() *resource.RetryError {
var err error
resp, err = conn.RequestSpotFleet(spotFleetOpts)

if isAWSErr(err, "InvalidSpotFleetRequestConfig", "") {
return resource.RetryableError(fmt.Errorf("Error creating Spot fleet request, retrying: %s", err))
}
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
// IAM is eventually consistent :/
if awsErr.Code() == "InvalidSpotFleetRequestConfig" {
return resource.RetryableError(
fmt.Errorf("Error creating Spot fleet request, retrying: %s", err))
}
}
return resource.NonRetryableError(err)
}
return nil
})

if isResourceTimeoutError(err) {
resp, err = conn.RequestSpotFleet(spotFleetOpts)
}

if err != nil {
return fmt.Errorf("Error requesting spot fleet: %s", err)
}
Expand Down
5 changes: 4 additions & 1 deletion aws/resource_aws_spot_instance_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ func resourceAwsSpotInstanceRequestCreate(d *schema.ResourceData, meta interface

var resp *ec2.RequestSpotInstancesOutput
err = resource.Retry(1*time.Minute, func() *resource.RetryError {
var err error
resp, err = conn.RequestSpotInstances(spotOpts)
// IAM instance profiles can take ~10 seconds to propagate in AWS:
// http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html#launch-instance-with-role-console
Expand All @@ -193,6 +192,10 @@ func resourceAwsSpotInstanceRequestCreate(d *schema.ResourceData, meta interface
return resource.NonRetryableError(err)
})

if isResourceTimeoutError(err) {
resp, err = conn.RequestSpotInstances(spotOpts)
}

if err != nil {
return fmt.Errorf("Error requesting spot instances: %s", err)
}
Expand Down

0 comments on commit f64f57a

Please sign in to comment.