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

[PR #1593/3d045fda backport][stable-6] autoscaling_group_info - Fix ValidationError when describing ASGs that have more than 20 Load Balancer Target Groups attached #1596

Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
bugfixes:
- autoscaling_group_info - fix ValidationError when describing an autoscaling group that has more than 20 target groups attached to it by breaking the request into chunks (https://github.com/ansible-collections/amazon.aws/pull/1593).
- autoscaling_group - fix ValidationError when describing an autoscaling group that has more than 20 target groups attached to it by breaking the request into chunks (https://github.com/ansible-collections/amazon.aws/pull/1593).
16 changes: 11 additions & 5 deletions plugins/modules/autoscaling_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,12 +901,18 @@ def get_properties(autoscaling_group):
if properties["target_group_arns"]:
elbv2_connection = module.client("elbv2")
tg_paginator = elbv2_connection.get_paginator("describe_target_groups")
tg_result = tg_paginator.paginate(TargetGroupArns=properties["target_group_arns"]).build_full_result()
target_groups = tg_result["TargetGroups"]
# Limit of 20 similar to https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_DescribeLoadBalancers.html
tg_chunk_size = 20
properties["target_group_names"] = []
tg_chunks = [
properties["target_group_arns"][i : i + tg_chunk_size]
for i in range(0, len(properties["target_group_arns"]), tg_chunk_size)
]
for chunk in tg_chunks:
tg_result = tg_paginator.paginate(TargetGroupArns=chunk).build_full_result()
properties["target_group_names"].extend([tg["TargetGroupName"] for tg in tg_result["TargetGroups"]])
else:
target_groups = []

properties["target_group_names"] = [tg["TargetGroupName"] for tg in target_groups]
properties["target_group_names"] = []

return properties

Expand Down
14 changes: 12 additions & 2 deletions plugins/modules/autoscaling_group_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,18 @@ def find_asgs(conn, module, name=None, tags=None):
if elbv2:
try:
tg_paginator = elbv2.get_paginator("describe_target_groups")
tg_result = tg_paginator.paginate(TargetGroupArns=asg["target_group_arns"]).build_full_result()
asg["target_group_names"] = [tg["TargetGroupName"] for tg in tg_result["TargetGroups"]]
# Limit of 20 similar to https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_DescribeLoadBalancers.html
tg_chunk_size = 20
asg["target_group_names"] = []
tg_chunks = [
asg["target_group_arns"][i : i + tg_chunk_size]
for i in range(0, len(asg["target_group_arns"]), tg_chunk_size)
]
for chunk in tg_chunks:
tg_result = tg_paginator.paginate(TargetGroupArns=chunk).build_full_result()
asg["target_group_names"].extend(
[tg["TargetGroupName"] for tg in tg_result["TargetGroups"]]
)
except is_boto3_error_code("TargetGroupNotFound"):
asg["target_group_names"] = []
except (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,8 @@

# Target group names have max length of 32 characters
- set_fact:
tg1_name: "{{ (resource_prefix + '-tg1' ) | regex_search('(.{1,32})$') }}"
tg2_name: "{{ (resource_prefix + '-tg2' ) | regex_search('(.{1,32})$') }}"
tg1_name: "ansible-test-{{tiny_prefix}}-asg-t1"
tg2_name: "ansible-test-{{tiny_prefix}}-asg-t2"
- name: create target group 1
elb_target_group:
name: '{{ tg1_name }}'
Expand Down