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

Batch up requests with more than 10 target group changes #10435

Merged
merged 3 commits into from
Oct 10, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 37 additions & 12 deletions aws/resource_aws_autoscaling_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -920,22 +920,47 @@ func resourceAwsAutoscalingGroupUpdate(d *schema.ResourceData, meta interface{})
add := expandStringList(ns.Difference(os).List())

if len(remove) > 0 {
_, err := conn.DetachLoadBalancerTargetGroups(&autoscaling.DetachLoadBalancerTargetGroupsInput{
AutoScalingGroupName: aws.String(d.Id()),
TargetGroupARNs: remove,
})
if err != nil {
return fmt.Errorf("Error updating Load Balancers Target Groups for AutoScaling Group (%s), error: %s", d.Id(), err)
// AWS API only supports adding/removing 10 at a time
var batches [][]*string

batchSize := 10

for batchSize < len(remove) {
remove, batches = remove[batchSize:], append(batches, remove[0:batchSize:batchSize])
}
batches = append(batches, remove)

for _, batch := range batches {
_, err := conn.DetachLoadBalancerTargetGroups(&autoscaling.DetachLoadBalancerTargetGroupsInput{
AutoScalingGroupName: aws.String(d.Id()),
TargetGroupARNs: batch,
})
if err != nil {
return fmt.Errorf("Error updating Load Balancers Target Groups for AutoScaling Group (%s), error: %s", d.Id(), err)
}
beezly marked this conversation as resolved.
Show resolved Hide resolved
}

}

if len(add) > 0 {
_, err := conn.AttachLoadBalancerTargetGroups(&autoscaling.AttachLoadBalancerTargetGroupsInput{
AutoScalingGroupName: aws.String(d.Id()),
TargetGroupARNs: add,
})
if err != nil {
return fmt.Errorf("Error updating Load Balancers Target Groups for AutoScaling Group (%s), error: %s", d.Id(), err)
batchSize := 10

var batches [][]*string

for batchSize < len(add) {
add, batches = add[batchSize:], append(batches, add[0:batchSize:batchSize])
}
batches = append(batches, add)

for _, batch := range batches {
_, err := conn.AttachLoadBalancerTargetGroups(&autoscaling.AttachLoadBalancerTargetGroupsInput{
AutoScalingGroupName: aws.String(d.Id()),
TargetGroupARNs: batch,
})

if err != nil {
return fmt.Errorf("Error updating Load Balancers Target Groups for AutoScaling Group (%s), error: %s", d.Id(), err)
}
beezly marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down