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

[Bug]: ASG drainGroup calls SetInstanceProtection even when not protected #36584

Closed
bstriner opened this issue Mar 26, 2024 · 4 comments · Fixed by #36586
Closed

[Bug]: ASG drainGroup calls SetInstanceProtection even when not protected #36584

bstriner opened this issue Mar 26, 2024 · 4 comments · Fixed by #36586
Labels
bug Addresses a defect in current functionality. service/autoscaling Issues and PRs that pertain to the autoscaling service.
Milestone

Comments

@bstriner
Copy link
Contributor

Terraform Core Version

1.7.5

AWS Provider Version

1.7.5

Affected Resource(s)

aws_autoscaling_group

Expected Behavior

If an instance isn't protected, don't make extra API calls to remove protection

Actual Behavior

Deleting an ASG that doesn't have scale in protection can fail with "not authorized to perform: autoscaling:SetInstanceProtection". Role needs the ability to remove instance protection to be able to delete instances that aren't protected. Instance protection is made useless and role cannot be least privilege.

Relevant Error/Panic Output Snippet

Error: disabling Auto Scaling Group (X) scale-in protections: AccessDenied: User: arn:aws:sts::X:assumed-role/X/GHActionsSession is not authorized to perform: autoscaling:SetInstanceProtection on resource: arn:aws:autoscaling:us-east-1:X:autoScalingGroup:X because no identity-based policy allows the autoscaling:SetInstanceProtection action

Terraform Configuration Files

resource "aws_autoscaling_group" "asg" {
name = var.namespace
vpc_zone_identifier = local.subnets
desired_capacity = 1
max_size = 1
min_size = 1

launch_template {
id = aws_launch_template.ecs_lt.id
version = "$Latest"
}

tag {
key = "AmazonECSManaged"
value = true
propagate_at_launch = true
}
}

Steps to Reproduce

Any ECS/EC2 setup if your role doesn't have SetInstanceProtection, or use an admin role and see unnecessary SetInstanceProtection calls in cloudtrail.

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

In this previous merged PR, there is a loop checking ProtectedFromScaleIn: #23187
https://github.com/hashicorp/terraform-provider-aws/pull/23187/files

var instanceIds []string
for _, instance := range g.Instances {
if aws.BoolValue(instance.ProtectedFromScaleIn) {
instanceIds = append(instanceIds, aws.StringValue(instance.InstanceId))
}
}

That code code moved around, the current implementation in drainGroup loops through all instances with no filter.

const batchSize = 50 // API limit.

Would you like to implement a fix?

Yes

@bstriner bstriner added the bug Addresses a defect in current functionality. label Mar 26, 2024
Copy link

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this 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.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@github-actions github-actions bot added the service/autoscaling Issues and PRs that pertain to the autoscaling service. label Mar 26, 2024
@terraform-aws-provider terraform-aws-provider bot added the needs-triage Waiting for first response or review from a maintainer. label Mar 26, 2024
bstriner added a commit to bstriner/terraform-provider-aws that referenced this issue Mar 26, 2024
@justinretzolk justinretzolk removed the needs-triage Waiting for first response or review from a maintainer. label Mar 26, 2024
Copy link

Warning

This issue has been closed, meaning that any additional comments are hard for our team to see. Please assume that the maintainers will not see them.

Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed.

@github-actions github-actions bot added this to the v5.43.0 milestone Mar 27, 2024
Copy link

This functionality has been released in v5.43.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 issue 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 similar to this, 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 Apr 28, 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants