-
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
Conversation
Hi @bflad! Are you sure this PR should be classified as enhancement? Initial issue was classified as a bug and, to me at least, it's a buggy behavior :) |
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.
This is a good start -- please see below and let us know if you have any questions.
@@ -286,9 +286,19 @@ func resourceAwsAppautoscalingPolicyCreate(d *schema.ResourceData, meta interfac | |||
|
|||
func resourceAwsAppautoscalingPolicyRead(d *schema.ResourceData, meta interface{}) error { | |||
p, err := getAwsAppautoscalingPolicy(d, meta) |
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.
The API call must be inside the resource.Retry()
loops to actually retry, otherwise it will continuously just loop with the same error without actually calling the API.
@@ -286,9 +286,19 @@ func resourceAwsAppautoscalingPolicyCreate(d *schema.ResourceData, meta interfac | |||
|
|||
func resourceAwsAppautoscalingPolicyRead(d *schema.ResourceData, meta interface{}) error { | |||
p, err := getAwsAppautoscalingPolicy(d, meta) | |||
err = resource.Retry(5*time.Minute, func() *resource.RetryError { | |||
if err != nil { | |||
if isAWSErr(err, "FailedResourceAccessException", "Rate exceeded") { |
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.
Nitpick: SDK provided constant available: applicationautoscaling.ErrCodeFailedResourceAccessException
@@ -321,6 +331,15 @@ func resourceAwsAppautoscalingPolicyUpdate(d *schema.ResourceData, meta interfac | |||
|
|||
log.Printf("[DEBUG] Application Autoscaling Update Scaling Policy: %#v", params) | |||
_, err := conn.PutScalingPolicy(¶ms) |
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.
Same here, the API call must be inside the resource.Retry()
@@ -345,8 +364,18 @@ 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 = conn.DeleteScalingPolicy(¶ms) |
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.
Same here, the API call must be inside the resource.Retry()
Thanks for the tips! I've updated PR. |
var err error | ||
p, err = getAwsAppautoscalingPolicy(d, meta) | ||
if err != nil { | ||
if awsErr, ok := err.(awserr.Error); ok { |
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.
if isAWSErr(err, applicationautoscaling.ErrCodeFailedResourceAccessException, "") {
return resource.RetryableError(err) | ||
} | ||
} | ||
} |
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.
We should return resource.NonRetryableError(err)
as the last statement inside the if err != nil
conditional so its passed up to the returned error, otherwise the outside code will not see these. I'll fix these on merge.
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.
Thanks for this! 🚀
6 tests passed (all tests)
=== RUN TestAccAWSAppautoScalingPolicy_nestedSchema
--- PASS: TestAccAWSAppautoScalingPolicy_nestedSchema (11.13s)
=== RUN TestAccAWSAppautoScalingPolicy_basic
--- PASS: TestAccAWSAppautoScalingPolicy_basic (33.12s)
=== RUN TestAccAWSAppautoScalingPolicy_spotFleetRequest
--- PASS: TestAccAWSAppautoScalingPolicy_spotFleetRequest (59.25s)
=== RUN TestAccAWSAppautoScalingPolicy_multiplePoliciesSameName
--- PASS: TestAccAWSAppautoScalingPolicy_multiplePoliciesSameName (114.54s)
=== RUN TestAccAWSAppautoScalingPolicy_multiplePoliciesSameResource
--- PASS: TestAccAWSAppautoScalingPolicy_multiplePoliciesSameResource (120.25s)
=== RUN TestAccAWSAppautoScalingPolicy_dynamoDb
--- PASS: TestAccAWSAppautoScalingPolicy_dynamoDb (254.36s)
Thanks a million! |
This has been released in version 1.20.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
Fixes #4285
Changes proposed in this pull request:
RetryableError
on read, update and delete. It was already on create but it wasn't' enough.Output from acceptance testing: