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

[WIP] add algorithm_type option for elb_target_group #282

Closed
wants to merge 7 commits into from
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
17 changes: 17 additions & 0 deletions plugins/modules/elb_target_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,17 @@
required: false
choices: ['instance', 'ip', 'lambda']
type: str
algorithm_type:
description:
- The algorithm type determines how the load balancer selects targets when routing requests.
The possible values are C(round_robin) or C(least_outstanding_requests).
- The algorithm type is only supported when the target is an instance or an IP address and the load balancer is
an application load balancer.
- The default is C(round_robin).
required: false
choices: ['round_robin', 'least_outstanding_requests']
type: str
default: round_robin
targets:
description:
- A list of targets to assign to the target group. This parameter defaults to an empty list. Unless you set the 'modify_targets' parameter then
Expand Down Expand Up @@ -227,6 +238,7 @@
health_check_path: /
successful_response_codes: "200,250-260"
target_type: ip
algorithm_type: least_outstanding_requests
targets:
- Id: 10.0.0.10
Port: 80
Expand Down Expand Up @@ -453,6 +465,7 @@ def create_or_update_target_group(connection, module):
new_target_group = False
params = dict()
target_type = module.params.get("target_type")
algorithm_type = module.params.get("algorithm_type")
params['Name'] = module.params.get("name")
params['TargetType'] = target_type
if target_type != "lambda":
Expand Down Expand Up @@ -740,6 +753,9 @@ def create_or_update_target_group(connection, module):
# Get current attributes
current_tg_attributes = get_tg_attributes(connection, module, tg['TargetGroupArn'])

if target_type in ['instance', 'ip'] and module.params.get("protocol").lower() in ['http', 'https']:
if algorithm_type != current_tg_attributes['load_balancing_algorithm_type']:
update_attributes.append({'Key': 'load_balancing.algorithm.type', 'Value': algorithm_type})
if deregistration_delay_timeout is not None:
if str(deregistration_delay_timeout) != current_tg_attributes['deregistration_delay_timeout_seconds']:
update_attributes.append({'Key': 'deregistration_delay.timeout_seconds', 'Value': str(deregistration_delay_timeout)})
Expand Down Expand Up @@ -836,6 +852,7 @@ def main():
successful_response_codes=dict(),
tags=dict(default={}, type='dict'),
target_type=dict(choices=['instance', 'ip', 'lambda']),
algorithm_type=dict(choices=['round_robin', 'least_outstanding_requests'], default='round_robin'),
targets=dict(type='list', elements='dict'),
unhealthy_threshold_count=dict(type='int'),
vpc_id=dict(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,36 @@
- result.target_health_descriptions.target.id == ec2.instance_ids[0]
- result.target_health_descriptions.target_health == healthy_state

- name: verify algorithm type is round robin
elb_target:
target_group_name: "{{ tg_name }}-used"
target_id: "{{ ec2.instance_ids[0] }}"
state: present
target_status: healthy
target_status_timeout: 400
algorithm_type: round_robin
register: result

- name: algorithm type is round robin
assert:
that:
- not result.changed

- name: change algorithm type to least_outstanding_requests
elb_target:
target_group_name: "{{ tg_name }}-used"
target_id: "{{ ec2.instance_ids[0] }}"
state: present
target_status: healthy
target_status_timeout: 400
algorithm_type: least_outstanding_requests
register: result

- name: algorithm type is least_outstanding_requests
assert:
that:
- result.changed

# ============================================================

- name: remove a target from used target group
Expand Down