adds resource retry to SpotInstanceRequestCreate (#8516)
so that the create process waits for IAM Instance profiles and roles to propagate before continuing, this has been taken from `resource_aws_instance`
This commit is contained in:
parent
a4fd7ce23b
commit
b673f4d972
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue