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

[Fix] Set instance protection can fail as instance can be already deleted from Autoscaling Group #35071

Merged

Conversation

MTB90
Copy link
Contributor

@MTB90 MTB90 commented Dec 27, 2023

Description

Set instance protection can fail when instance, will be already removed from autoscaling group.
Method drainGroup is first updating AutoScalingGroup with {DesiredCapacity: 0, MinSize:0, MaxSize: 0}
next ensure that instances are not prevented from scaling in, as make sens updating autoscaling group as soon as posible.
Is posible that SetInstanceProtectionWithContext will fail, this can happen at least in two cases:

  1. API will be throttled for few sec by other client calls, but when throttling ends instance can be already fully removed
    so then SetInstanceProtectionWithContext return ValidationError

  2. The number of instances in autoscaling group is large, there will be multiple requests to run SetInstanceProtectionWithContext as they are run with package of 50 instances there is posibility that in the one of this package there will be instance that will be already removed from ASG

I faced that issue when I run multiple terraforms at the same time, and dude AWS API throtlled limits
image

I got this error:

module.cluster.aws_autoscaling_group.worker_autoscaling_grp: Still destroying... [id=56578271-cabc-466d-8855-c6c29f3f8d27us-east-2b, 3m10s elapsed]
module.cluster.aws_autoscaling_group.worker_autoscaling_grp: Still destroying... [id=56578271-cabc-466d-8855-c6c29f3f8d27us-east-2b, 3m20s elapsed]
module.cluster.aws_autoscaling_group.worker_autoscaling_grp: Still destroying... [id=56578271-cabc-466d-8855-c6c29f3f8d27us-east-2b, 3m30s elapsed]
module.cluster.aws_autoscaling_group.worker_autoscaling_grp: Still destroying... [id=56578271-cabc-466d-8855-c6c29f3f8d27us-east-2b, 3m40s elapsed]
module.cluster.aws_autoscaling_group.worker_autoscaling_grp: Still destroying... [id=56578271-cabc-466d-8855-c6c29f3f8d27us-east-2b, 3m50s elapsed]
╷
│ Error: disabling Auto Scaling Group (56578271-cabc-466d-8855-c6c29f3f8d27us-east-2b) scale-in protections: ValidationError: The instance i-08a6ea2f114bc84e3 is not part of Auto Scaling group 56578271-cabc-466d-8855-c6c29f3f8d27us-east-2b.
│ 	status code: 400, request id: e005323b-dff4-479b-90b8-b192300b5c12

Imo if instance is already fully removed, fail in disabling scale-in protections should not fail terraform destroy
also depends on if there is one instance or more instances that are not a part of autoscaling group any more the error contain:
The instance <instance> is not part of Auto Scaling group ...
or
The instances <instance>, <instance> are not part of Auto Scaling group ...

Output from Acceptance Testing

%  make testacc TESTS="TestAccAutoScalingGroup_Destroy" PKG=autoscaling
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/autoscaling/... -v -count 1 -parallel 20 -run='TestAccAutoScalingGroup_Destroy'  -timeout 360m
=== RUN   TestAccAutoScalingGroup_Destroy_whenProtectedFromScaleIn
=== PAUSE TestAccAutoScalingGroup_Destroy_whenProtectedFromScaleIn
=== CONT  TestAccAutoScalingGroup_Destroy_whenProtectedFromScaleIn
--- PASS: TestAccAutoScalingGroup_Destroy_whenProtectedFromScaleIn (224.95s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/autoscaling        225.057s

...

Copy link

Community Note

Voting for Prioritization

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

For Submitters

  • Review the contribution guide relating to the type of change you are making to ensure all of the necessary steps have been taken.
  • For new resources and data sources, use skaff to generate scaffolding with comments detailing common expectations.
  • Whether or not the branch has been rebased will not impact prioritization, but doing so is always a welcome surprise.

@github-actions github-actions bot added service/autoscaling Issues and PRs that pertain to the autoscaling service. size/XS Managed by automation to categorize the size of a PR. labels Dec 27, 2023
@terraform-aws-provider terraform-aws-provider bot added the needs-triage Waiting for first response or review from a maintainer. label Dec 27, 2023
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome @MTB90 👋

It looks like this is your first Pull Request submission to the Terraform AWS Provider! If you haven’t already done so please make sure you have checked out our CONTRIBUTOR guide and FAQ to make sure your contribution is adhering to best practice and has all the necessary elements in place for a successful approval.

Also take a look at our FAQ which details how we prioritize Pull Requests for inclusion.

Thanks again, and welcome to the community! 😃

@MTB90 MTB90 marked this pull request as ready for review December 29, 2023 10:56
@ewbankkit ewbankkit added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Jan 2, 2024
Copy link
Contributor

@ewbankkit ewbankkit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀.

% make testacc TESTARGS='-run=TestAccAutoScalingGroup_Destroy\|TestAccAutoScalingGroup_basic' PKG=autoscaling ACCTEST_PARALLELISM=2
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/autoscaling/... -v -count 1 -parallel 2  -run=TestAccAutoScalingGroup_Destroy\|TestAccAutoScalingGroup_basic -timeout 360m
=== RUN   TestAccAutoScalingGroup_basic
=== PAUSE TestAccAutoScalingGroup_basic
=== RUN   TestAccAutoScalingGroup_Destroy_whenProtectedFromScaleIn
=== PAUSE TestAccAutoScalingGroup_Destroy_whenProtectedFromScaleIn
=== CONT  TestAccAutoScalingGroup_basic
=== CONT  TestAccAutoScalingGroup_Destroy_whenProtectedFromScaleIn
--- PASS: TestAccAutoScalingGroup_basic (50.53s)
--- PASS: TestAccAutoScalingGroup_Destroy_whenProtectedFromScaleIn (165.53s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/autoscaling	171.230s

@ewbankkit
Copy link
Contributor

@MTB90 Thanks for the contribution 🎉 👏.

@ewbankkit ewbankkit merged commit 0aac2f6 into hashicorp:main Jan 2, 2024
36 checks passed
@github-actions github-actions bot added this to the v5.32.0 milestone Jan 2, 2024
Copy link

This functionality has been released in v5.32.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. Thank you!

Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 13, 2024
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. service/autoscaling Issues and PRs that pertain to the autoscaling service. 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.

2 participants