-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
resource/aws_appautoscaling_policy: retry on rate exceeded during read, update and delete #4594
Merged
+42
−7
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import ( | |
"time" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/awserr" | ||
"github.com/aws/aws-sdk-go/service/applicationautoscaling" | ||
"github.com/hashicorp/terraform/helper/hashcode" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
|
@@ -256,7 +257,7 @@ func resourceAwsAppautoscalingPolicyCreate(d *schema.ResourceData, meta interfac | |
|
||
log.Printf("[DEBUG] ApplicationAutoScaling PutScalingPolicy: %#v", params) | ||
var resp *applicationautoscaling.PutScalingPolicyOutput | ||
err = resource.Retry(1*time.Minute, func() *resource.RetryError { | ||
err = resource.Retry(2*time.Minute, func() *resource.RetryError { | ||
var err error | ||
resp, err = conn.PutScalingPolicy(¶ms) | ||
if err != nil { | ||
|
@@ -285,10 +286,24 @@ func resourceAwsAppautoscalingPolicyCreate(d *schema.ResourceData, meta interfac | |
} | ||
|
||
func resourceAwsAppautoscalingPolicyRead(d *schema.ResourceData, meta interface{}) error { | ||
p, err := getAwsAppautoscalingPolicy(d, meta) | ||
var p *applicationautoscaling.ScalingPolicy | ||
|
||
err := resource.Retry(2*time.Minute, func() *resource.RetryError { | ||
var err error | ||
p, err = getAwsAppautoscalingPolicy(d, meta) | ||
if err != nil { | ||
if awsErr, ok := err.(awserr.Error); ok { | ||
if awsErr.Code() == applicationautoscaling.ErrCodeFailedResourceAccessException { | ||
return resource.RetryableError(err) | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should |
||
return nil | ||
}) | ||
if err != nil { | ||
return err | ||
return fmt.Errorf("Failed to read scaling policy: %s", err) | ||
} | ||
|
||
if p == nil { | ||
log.Printf("[WARN] Application AutoScaling Policy (%s) not found, removing from state", d.Id()) | ||
d.SetId("") | ||
|
@@ -320,7 +335,17 @@ func resourceAwsAppautoscalingPolicyUpdate(d *schema.ResourceData, meta interfac | |
} | ||
|
||
log.Printf("[DEBUG] Application Autoscaling Update Scaling Policy: %#v", params) | ||
_, err := conn.PutScalingPolicy(¶ms) | ||
err := resource.Retry(2*time.Minute, func() *resource.RetryError { | ||
_, err := conn.PutScalingPolicy(¶ms) | ||
if err != nil { | ||
if awsErr, ok := err.(awserr.Error); ok { | ||
if awsErr.Code() == applicationautoscaling.ErrCodeFailedResourceAccessException { | ||
return resource.RetryableError(err) | ||
} | ||
} | ||
} | ||
return nil | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("Failed to update scaling policy: %s", err) | ||
} | ||
|
@@ -345,10 +370,20 @@ func resourceAwsAppautoscalingPolicyDelete(d *schema.ResourceData, meta interfac | |
ServiceNamespace: aws.String(d.Get("service_namespace").(string)), | ||
} | ||
log.Printf("[DEBUG] Deleting Application AutoScaling Policy opts: %#v", params) | ||
if _, err := conn.DeleteScalingPolicy(¶ms); err != nil { | ||
return fmt.Errorf("Failed to delete autoscaling policy: %s", err) | ||
err = resource.Retry(2*time.Minute, func() *resource.RetryError { | ||
_, err = conn.DeleteScalingPolicy(¶ms) | ||
if err != nil { | ||
if awsErr, ok := err.(awserr.Error); ok { | ||
if awsErr.Code() == applicationautoscaling.ErrCodeFailedResourceAccessException { | ||
return resource.RetryableError(err) | ||
} | ||
} | ||
} | ||
return nil | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("Failed to delete scaling policy: %s", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I was not clear earlier. We can still use the
isAWSErr()
helper here to keep the code cleaner -- I'll fix these on merge.