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_target: Prevent state removal at creation #11819

Conversation

camlow325
Copy link
Contributor

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Closes #11811

Release note for CHANGELOG:

* resource/aws_appautoscaling_target: Prevent state removal of resource immediately after creation due to eventual consistency ([#10549](https://github.com/terraform-providers/terraform-provider-aws/issues/11811))

The AWS application-autoscaling service has eventual consistency considerations. The aws_appautoscaling_target resource immediately tries to read a scaling target after creation. If the target is not found, the application-autoscaling service returns a 200 OK with an empty list of scaling targets. Since no scaling target is present, the aws_appautoscaling_target resource removes the created resource from state, leading to a "produced an unexpected new value for was present,
but now absent" error.

With the changes in this commit, the empty list of scaling targets in the response for the newly created resource will result in a NotFoundError being returned and a retry of the read request. A subsequent retry should hopefully be successful, leading to the state being preserved.

Output from acceptance testing:

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSAppautoScalingTarget_'
...
--- PASS: TestAccAWSAppautoScalingTarget_multipleTargets (30.77s)
--- PASS: TestAccAWSAppautoScalingTarget_optionalRoleArn (32.50s)
--- PASS: TestAccAWSAppautoScalingTarget_spotFleetRequest (77.50s)
--- PASS: TestAccAWSAppautoScalingTarget_basic (107.66s)
--- PASS: TestAccAWSAppautoScalingTarget_emrCluster (783.20s)

References
* hashicorp#11811

The AWS application-autoscaling service has eventual consistency
considerations. The `aws_appautoscaling_target` resource immediately
tries to read a scaling target after creation. If the target is not
found, the application-autoscaling service returns a 200 OK with an
empty list of scaling targets. Since no scaling target is present, the
`aws_appautoscaling_target` resource removes the created resource from
state, leading to a "produced an unexpected new value for was present,
but now absent" error.

With the changes in this commit, the empty list of scaling targets in
the response for the newly created resource will result in a
NotFoundError being returned and a retry of the read request. A
subsequent retry should hopefully be successful, leading to the state
being preserved.

Output from acceptance testing:

```
> make testacc TEST=./aws TESTARGS='-run=TestAccAWSAppautoScalingTarget_'
...
--- PASS: TestAccAWSAppautoScalingTarget_multipleTargets (30.77s)
--- PASS: TestAccAWSAppautoScalingTarget_optionalRoleArn (32.50s)
--- PASS: TestAccAWSAppautoScalingTarget_spotFleetRequest (77.50s)
--- PASS: TestAccAWSAppautoScalingTarget_basic (107.66s)
--- PASS: TestAccAWSAppautoScalingTarget_emrCluster (783.20s)
```
@camlow325 camlow325 requested a review from a team January 30, 2020 23:56
@ghost ghost added size/XS Managed by automation to categorize the size of a PR. needs-triage Waiting for first response or review from a maintainer. service/applicationautoscaling labels Jan 30, 2020
@bflad bflad added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Jan 31, 2020
@bflad bflad added this to the v2.48.0 milestone Jan 31, 2020
@bflad bflad self-assigned this Jan 31, 2020
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.

Nice investigative work and implementation, @camlow325 🚀

Output from acceptance testing:

--- PASS: TestAccAWSAppautoScalingTarget_optionalRoleArn (15.68s)
--- PASS: TestAccAWSAppautoScalingTarget_multipleTargets (16.71s)
--- PASS: TestAccAWSAppautoScalingTarget_spotFleetRequest (59.88s)
--- PASS: TestAccAWSAppautoScalingTarget_basic (71.08s)
--- PASS: TestAccAWSAppautoScalingTarget_emrCluster (838.51s)

@bflad bflad merged commit b069a0b into hashicorp:master Jan 31, 2020
bflad added a commit that referenced this pull request Jan 31, 2020
@ghost
Copy link

ghost commented Feb 7, 2020

This has been released in version 2.48.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@ghost
Copy link

ghost commented Mar 27, 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 Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. size/XS Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws_appautoscaling_target resource produced new value for was present but now absent
2 participants