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

tags should retry without time bounds on EC2 throttling #3586

Merged
merged 4 commits into from
Nov 14, 2018
Merged
Changes from 2 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
104 changes: 94 additions & 10 deletions aws/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,35 @@ func setVolumeTags(conn *ec2.EC2, d *schema.ResourceData) error {
if err != nil {
ec2err, ok := err.(awserr.Error)
if ok && strings.Contains(ec2err.Code(), ".NotFound") {
return resource.RetryableError(err) // retry
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
if err != nil {
return err
domdom82 marked this conversation as resolved.
Show resolved Hide resolved
if !isResourceTimeoutError(err) && !isAWSErr(err, "InvalidParameterValueException", "Your request has been throttled by EC2") {
domdom82 marked this conversation as resolved.
Show resolved Hide resolved
return err
}
// Allow additional time for slower uploads or EC2 throttling
err := resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
log.Printf("[DEBUG] Removing volume tags: %#v from %s", remove, d.Id())
_, err := conn.DeleteTags(&ec2.DeleteTagsInput{
Resources: volumeIds,
Tags: remove,
})
if err != nil {
if isAWSErr(err, "InvalidParameterValueException", "Your request has been throttled by EC2") {
log.Printf("[DEBUG] Received %s, retrying DeleteTags", err)
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
if err != nil {
return err
}
}
}
if len(create) > 0 {
Expand All @@ -113,14 +134,35 @@ func setVolumeTags(conn *ec2.EC2, d *schema.ResourceData) error {
if err != nil {
ec2err, ok := err.(awserr.Error)
if ok && strings.Contains(ec2err.Code(), ".NotFound") {
return resource.RetryableError(err) // retry
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
if err != nil {
return err
if !isResourceTimeoutError(err) && !isAWSErr(err, "InvalidParameterValueException", "Your request has been throttled by EC2") {
return err
}
// Allow additional time for slower uploads or EC2 throttling
err := resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
log.Printf("[DEBUG] Creating vol tags: %s for %s", create, d.Id())
_, err := conn.CreateTags(&ec2.CreateTagsInput{
Resources: volumeIds,
Tags: create,
})
if err != nil {
if isAWSErr(err, "InvalidParameterValueException", "Your request has been throttled by EC2") {
log.Printf("[DEBUG] Received %s, retrying CreateTags", err)
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
if err != nil {
return err
}
}
}
}
Expand All @@ -139,7 +181,7 @@ func setTags(conn *ec2.EC2, d *schema.ResourceData) error {

// Set tags
if len(remove) > 0 {
err := resource.Retry(5*time.Minute, func() *resource.RetryError {
err := resource.Retry(2*time.Minute, func() *resource.RetryError {
log.Printf("[DEBUG] Removing tags: %#v from %s", remove, d.Id())
_, err := conn.DeleteTags(&ec2.DeleteTagsInput{
Resources: []*string{aws.String(d.Id())},
Expand All @@ -148,18 +190,39 @@ func setTags(conn *ec2.EC2, d *schema.ResourceData) error {
if err != nil {
ec2err, ok := err.(awserr.Error)
if ok && strings.Contains(ec2err.Code(), ".NotFound") {
return resource.RetryableError(err) // retry
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
if err != nil {
return err
if !isResourceTimeoutError(err) && !isAWSErr(err, "InvalidParameterValueException", "Your request has been throttled by EC2") {
return err
}
// Allow additional time for slower uploads or EC2 throttling
err := resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
log.Printf("[DEBUG] Removing tags: %#v from %s", remove, d.Id())
_, err := conn.DeleteTags(&ec2.DeleteTagsInput{
Resources: []*string{aws.String(d.Id())},
Tags: remove,
})
if err != nil {
if isAWSErr(err, "InvalidParameterValueException", "Your request has been throttled by EC2") {
log.Printf("[DEBUG] Received %s, retrying DeleteTags", err)
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
if err != nil {
return err
}
}
}
if len(create) > 0 {
err := resource.Retry(5*time.Minute, func() *resource.RetryError {
err := resource.Retry(2*time.Minute, func() *resource.RetryError {
log.Printf("[DEBUG] Creating tags: %s for %s", create, d.Id())
_, err := conn.CreateTags(&ec2.CreateTagsInput{
Resources: []*string{aws.String(d.Id())},
Expand All @@ -168,14 +231,35 @@ func setTags(conn *ec2.EC2, d *schema.ResourceData) error {
if err != nil {
ec2err, ok := err.(awserr.Error)
if ok && strings.Contains(ec2err.Code(), ".NotFound") {
return resource.RetryableError(err) // retry
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
if err != nil {
return err
if !isResourceTimeoutError(err) && !isAWSErr(err, "InvalidParameterValueException", "Your request has been throttled by EC2") {
return err
}
// Allow additional time for slower uploads or EC2 throttling
err := resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
log.Printf("[DEBUG] Creating tags: %s for %s", create, d.Id())
_, err := conn.CreateTags(&ec2.CreateTagsInput{
Resources: []*string{aws.String(d.Id())},
Tags: create,
})
if err != nil {
if isAWSErr(err, "InvalidParameterValueException", "Your request has been throttled by EC2") {
log.Printf("[DEBUG] Received %s, retrying CreateTags", err)
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
if err != nil {
return err
}
}
}
}
Expand Down