Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds resource retry to SpotInstanceRequestCreate #8516

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep this simple here, since you are not doing anything special with the InvalidParameterValue specific message, besides logging, that is. You could simply check for it, then log a message that there was an error, and use err.Message() (need to assert right type, though) and then return resource.RetryableError(err) as usual.

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