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

resource/aws_appautoscaling_policy: retry on rate exceeded during read, update and delete #4594

Merged
merged 1 commit into from
May 21, 2018

Conversation

s-maj
Copy link
Contributor

@s-maj s-maj commented May 18, 2018

Fixes #4285

Changes proposed in this pull request:

  • Adds RetryableError on read, update and delete. It was already on create but it wasn't' enough.

Output from acceptance testing:

make testacc TEST=./aws TESTARGS='-run=TestAccAWSAppautoScalingPolicy'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSAppautoScalingPolicy -timeout 120m
=== RUN   TestAccAWSAppautoScalingPolicy_basic
--- PASS: TestAccAWSAppautoScalingPolicy_basic (59.41s)
=== RUN   TestAccAWSAppautoScalingPolicy_nestedSchema
--- PASS: TestAccAWSAppautoScalingPolicy_nestedSchema (85.70s)
=== RUN   TestAccAWSAppautoScalingPolicy_spotFleetRequest
--- PASS: TestAccAWSAppautoScalingPolicy_spotFleetRequest (107.47s)
=== RUN   TestAccAWSAppautoScalingPolicy_dynamoDb
--- PASS: TestAccAWSAppautoScalingPolicy_dynamoDb (174.32s)
=== RUN   TestAccAWSAppautoScalingPolicy_multiplePoliciesSameName
--- PASS: TestAccAWSAppautoScalingPolicy_multiplePoliciesSameName (170.50s)
=== RUN   TestAccAWSAppautoScalingPolicy_multiplePoliciesSameResource
--- PASS: TestAccAWSAppautoScalingPolicy_multiplePoliciesSameResource (168.86s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	766.302s

@ghost ghost added the size/M Managed by automation to categorize the size of a PR. label May 18, 2018
@s-maj s-maj changed the title aws_appautoscaling_policy: retry on rate exceeded during read, update and delete resource/aws_appautoscaling_policy: retry on rate exceeded during read, update and delete May 18, 2018
@bflad bflad added enhancement Requests to existing resources that expand the functionality or scope. service/applicationautoscaling labels May 21, 2018
@s-maj
Copy link
Contributor Author

s-maj commented May 21, 2018

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 :)

Copy link
Contributor

@bflad bflad left a 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)
Copy link
Contributor

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") {
Copy link
Contributor

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(&params)
Copy link
Contributor

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(&params); err != nil {
return fmt.Errorf("Failed to delete autoscaling policy: %s", err)
_, err = conn.DeleteScalingPolicy(&params)
Copy link
Contributor

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()

@ghost ghost added the size/M Managed by automation to categorize the size of a PR. label May 21, 2018
@s-maj
Copy link
Contributor Author

s-maj commented May 21, 2018

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 {
Copy link
Contributor

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)
}
}
}
Copy link
Contributor

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.

@bflad bflad added this to the v1.20.0 milestone May 21, 2018
Copy link
Contributor

@bflad bflad left a 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)

@bflad bflad merged commit e930e2a into hashicorp:master May 21, 2018
bflad added a commit that referenced this pull request May 21, 2018
@s-maj
Copy link
Contributor Author

s-maj commented May 21, 2018

Thanks a million!

@s-maj s-maj deleted the GH-4285 branch May 21, 2018 23:37
@bflad
Copy link
Contributor

bflad commented May 23, 2018

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.

@ghost
Copy link

ghost commented Apr 5, 2020

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!

@ghost ghost locked and limited conversation to collaborators Apr 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. size/M Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Created DynamoDB autoscaling policy fails if there is the Cloudwatch Api is throttled (eg rate limited)
2 participants