Skip to content

Commit

Permalink
adds resource retry to SpotInstanceRequestCreate (#8516)
Browse files Browse the repository at this point in the history
so that the create process waits for IAM Instance profiles and roles to propagate before continuing, this has been taken from `resource_aws_instance`
  • Loading branch information
richardbowden authored and stack72 committed Aug 29, 2016
1 parent a4fd7ce commit b673f4d
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion builtin/providers/aws/resource_aws_spot_instance_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,25 @@ func resourceAwsSpotInstanceRequestCreate(d *schema.ResourceData, meta interface

// Make the spot instance request
log.Printf("[DEBUG] Requesting spot bid opts: %s", spotOpts)
resp, err := conn.RequestSpotInstances(spotOpts)

var resp *ec2.RequestSpotInstancesOutput
err = resource.Retry(15*time.Second, 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
if isAWSErr(err, "InvalidParameterValue", "Invalid IAM Instance Profile") {
log.Printf("[DEBUG] Invalid IAM Instance Profile referenced, retrying...")
return resource.RetryableError(err)
}
// IAM roles can also take time to propagate in AWS:
if isAWSErr(err, "InvalidParameterValue", " has no associated IAM Roles") {
log.Printf("[DEBUG] IAM Instance Profile appears to have no IAM roles, retrying...")
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
})

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

0 comments on commit b673f4d

Please sign in to comment.