Skip to content

Commit

Permalink
Merge pull request #36586 from bstriner/patch-1
Browse files Browse the repository at this point in the history
ASG check instance protection
  • Loading branch information
ewbankkit authored Mar 27, 2024
2 parents 78729c3 + bd19065 commit 56092e7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .changelog/36586.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_autoscaling_group: Don't attempt to remove scale-in protection from instances that don't have the feature enabled
```
16 changes: 10 additions & 6 deletions internal/service/autoscaling/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -1850,15 +1850,19 @@ func drainGroup(ctx context.Context, conn *autoscaling.AutoScaling, name string,
// desired capacity is set to 0. There is also the possibility that this ASG
// no longer applies scale-in protection to new instances, but there's still
// old ones that have it.

//
// Filter by ProtectedFromScaleIn to avoid unnecessary API calls (#36584)
var instanceIDs []string
for _, instance := range instances {
if aws.BoolValue(instance.ProtectedFromScaleIn) {
instanceIDs = append(instanceIDs, aws.StringValue(instance.InstanceId))
}
}
const batchSize = 50 // API limit.
for _, chunk := range tfslices.Chunks(instances, batchSize) {
instanceIDs := tfslices.ApplyToAll(chunk, func(v *autoscaling.Instance) string {
return aws.StringValue(v.InstanceId)
})
for _, chunk := range tfslices.Chunks(instanceIDs, batchSize) {
input := &autoscaling.SetInstanceProtectionInput{
AutoScalingGroupName: aws.String(name),
InstanceIds: aws.StringSlice(instanceIDs),
InstanceIds: aws.StringSlice(chunk),
ProtectedFromScaleIn: aws.Bool(false),
}

Expand Down

0 comments on commit 56092e7

Please sign in to comment.