Skip to content

Commit

Permalink
Add deregistration_connection_termination to elb_target_group (#913) (#…
Browse files Browse the repository at this point in the history
…926)

[PR #913/55962ff2 backport][stable-3] Add deregistration_connection_termination to elb_target_group

This is a backport of PR #913 as merged into main (55962ff).
SUMMARY
Adding support for the deregistration_connection_termination param in the elb_target_group module.
Along with this I've enabled and fixed up the integration tests.
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
elb_target_group
ADDITIONAL INFORMATION
The API param is deregistration_delay.connection_termination.enabled
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/elbv2.html#ElasticLoadBalancingv2.Client.describe_target_group_attributes
  • Loading branch information
patchback[bot] authored Feb 4, 2022
1 parent c46b0a4 commit 0fde2d4
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 165 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/913-tg-dereg-conn-param.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- elb_target_group - add support for parameter ``deregistration_connection_termination`` (https://github.com/ansible-collections/community.aws/pull/913).
22 changes: 21 additions & 1 deletion plugins/modules/elb_target_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
- The amount time for Elastic Load Balancing to wait before changing the state of a deregistering target from draining to unused.
The range is 0-3600 seconds.
type: int
deregistration_connection_termination:
description:
- Indicates whether the load balancer terminates connections at the end of the deregistration timeout.
type: bool
default: false
required: false
version_added: 3.1.0
health_check_protocol:
description:
- The protocol the load balancer uses when performing health checks on targets.
Expand Down Expand Up @@ -305,6 +312,11 @@
returned: when state present
type: int
sample: 300
deregistration_connection_termination:
description: Indicates whether the load balancer terminates connections at the end of the deregistration timeout.
returned: when state present
type: bool
sample: True
health_check_interval_seconds:
description: The approximate amount of time, in seconds, between health checks of an individual target.
returned: when state present
Expand Down Expand Up @@ -425,7 +437,7 @@ def get_tg_attributes(connection, module, tg_arn):
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg="Couldn't get target group attributes")

# Replace '.' with '_' in attribute key names to make it more Ansibley
# Replace '.' with '_' in attribute key names to make it more Ansible friendly
return dict((k.replace('.', '_'), v) for k, v in tg_attributes.items())


Expand Down Expand Up @@ -486,6 +498,7 @@ def create_or_update_target_group(connection, module):
tags = module.params.get("tags")
purge_tags = module.params.get("purge_tags")
deregistration_delay_timeout = module.params.get("deregistration_delay_timeout")
deregistration_connection_termination = module.params.get("deregistration_connection_termination")
stickiness_enabled = module.params.get("stickiness_enabled")
stickiness_lb_cookie_duration = module.params.get("stickiness_lb_cookie_duration")
stickiness_type = module.params.get("stickiness_type")
Expand Down Expand Up @@ -767,6 +780,9 @@ def create_or_update_target_group(connection, module):
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)})
if deregistration_connection_termination is not None:
if deregistration_connection_termination and current_tg_attributes.get('deregistration_delay_connection_termination_enabled') != "true":
update_attributes.append({'Key': 'deregistration_delay.connection_termination.enabled', 'Value': 'true'})
if stickiness_enabled is not None:
if stickiness_enabled and current_tg_attributes['stickiness_enabled'] != "true":
update_attributes.append({'Key': 'stickiness.enabled', 'Value': 'true'})
Expand Down Expand Up @@ -855,6 +871,7 @@ def main():
'HTTPS', 'TCP', 'TLS', 'UDP', 'TCP_UDP']
argument_spec = dict(
deregistration_delay_timeout=dict(type='int'),
deregistration_connection_termination=dict(type='bool', default=False),
health_check_protocol=dict(choices=protocols_list),
health_check_port=dict(),
health_check_path=dict(),
Expand Down Expand Up @@ -897,6 +914,9 @@ def main():
connection = module.client('elbv2', retry_decorator=AWSRetry.jittered_backoff(retries=10))

if module.params.get('state') == 'present':
if module.params.get('protocol') in ['http', 'https', 'HTTP', 'HTTPS'] and module.params.get('deregistration_connection_termination', None):
module.fail_json(msg="A target group with HTTP/S protocol does not support setting deregistration_connection_termination")

create_or_update_target_group(connection, module)
else:
delete_target_group(connection, module)
Expand Down
4 changes: 1 addition & 3 deletions tests/integration/targets/elb_target/aliases
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
cloud/aws
# currently broken
# e.g: https://3d7660cef77b937e1585-998cb574f2547d50f5110d6a2d4ac097.ssl.cf1.rackcdn.com/636/067f6f84c20701ccf4bf0654471613af598c6e89/check/ansible-test-cloud-integration-aws-py36_2/be6c4b3/job-output.txt
disabled

slow
elb_target_group
5 changes: 3 additions & 2 deletions tests/integration/targets/elb_target/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ unique_id: "ansible-test-{{ tiny_prefix }}"

lambda_role_name: '{{ unique_id }}-elb-target'
lambda_name: '{{ unique_id }}-elb-target'
elb_target_group_name: "{{ unique_id }}-elb-tg"
elb_target_group_name: "{{ unique_id }}-elb"

# Defaults used by the EC2 based test
ec2_ami_name: 'amzn2-ami-hvm-2.0.20190612-x86_64-gp2'
tg_name: "{{ unique_id }}-tg"
tg_tcpudp_name: "{{ unique_id }}-tgtcpudp"
tg_used_name: "{{ unique_id }}-tgu"
tg_tcpudp_name: "{{ unique_id }}-udp"
lb_name: "{{ unique_id }}-lb"
healthy_state:
state: 'healthy'
3 changes: 3 additions & 0 deletions tests/integration/targets/elb_target/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies:
- prepare_tests
- setup_ec2
Loading

0 comments on commit 0fde2d4

Please sign in to comment.