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

Collect arguments for application session stickiness and update docs #548

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions changelogs/fragments/548-elb-target-group-app-stickiness.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- elb_target_group - Add elb target group attributes ``stickiness_app_cookie_name`` and ``stickiness_app_cookie_duration_seconds``. Also update docs for stickiness_type to mention application cookie (https://github.com/ansible-collections/community.aws/pull/548)
40 changes: 38 additions & 2 deletions docs/community.aws.elb_target_group_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,37 @@ Parameters
<td>
</td>
<td>
<div>The time period, in seconds, during which requests from a client should be routed to the same target. After this time period expires, the load balancer-generated cookie is considered stale. The range is 1 second to 1 week (604800 seconds).</div>
<div>The time period, in seconds, during which requests from a client should be routed to the same target. After this time period expires, the load balancer-generated cookie is considered stale. The range is 1 second to 1 week (604800 seconds). Assumes <code>stickiness_type</code> is set to <code>lb_cookie</code>.</div>
</td>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>stickiness_app_cookie_duration</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">integer</span>
</div>
</td>
<td>
</td>
<td>
<div>The time period, in seconds, during which requests from a client should be routed to the same target. After this time period expires, the load application-generated cookie is considered stale. The range is 1 second to 1 week (604800 seconds). Assumes <code>stickiness_type</code> is <code>app_cookie</code>.</div>
</td>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>stickiness_app_cookie_name</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">string</span>
</div>
</td>
<td>
</td>
<td>
<div>The name of the application session cookie. Assumes <code>stickiness_type</code> is set to <code>app_cookie</code>.</div>
</td>
</tr>
<tr>
Expand All @@ -481,10 +511,16 @@ Parameters
</div>
</td>
<td>

<ul style="margin: 0; padding: 0"><b>Choices:</b>
<li><div style="color: blue"><b>lb_cookie</b>&nbsp;&larr;</div></li>
<li>app_cookie</li>
<li>source_ip</li>
</ul>
</td>
<td>
<div>The type of sticky sessions.</div>
<div>If not set AWS will default to <code>lb_cookie</code> for Application Load Balancers or <code>source_ip</code> for Network Load Balancers.</div>
<div>If not set AWS will default to <code>lb_cookie</code> for Application Load Balancers or <code>source_ip</code> for Network Load Balancers. For Application Load Balancers it is also possible to specify <code>app_cookie</code> for application managed cookies. Assumes <code>stickiness_enabled</code> is set to <code>yes</code>.</div>
</td>
</tr>
<tr>
Expand Down
24 changes: 24 additions & 0 deletions plugins/modules/elb_target_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,23 @@
- The time period, in seconds, during which requests from a client should be routed to the same target. After this time period expires, the load
balancer-generated cookie is considered stale. The range is 1 second to 1 week (604800 seconds).
type: int
stickiness_app_cookie_duration:
description:
- The time period, in seconds, during which requests from a client
should be routed to the same target. After this time period expires,
the application-generated cookie is considered stale. The range is 1 second to 1 week (604800 seconds).
type: int
tremble marked this conversation as resolved.
Show resolved Hide resolved
version_added: 1.5.0
stickiness_app_cookie_name:
description:
- The name of the application cookie. Required if C(stickiness_type) is
C(app_cookie).
tremble marked this conversation as resolved.
Show resolved Hide resolved
type: str
tremble marked this conversation as resolved.
Show resolved Hide resolved
version_added: 1.5.0
stickiness_type:
description:
- The type of sticky sessions.
- C(lb_cookie), C(app_cookie) or C(source_ip)
tremble marked this conversation as resolved.
Show resolved Hide resolved
- If not set AWS will default to C(lb_cookie) for Application Load Balancers or C(source_ip) for Network Load Balancers.
type: str
successful_response_codes:
Expand Down Expand Up @@ -466,6 +480,8 @@ def create_or_update_target_group(connection, module):
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")
stickiness_app_cookie_duration = module.params.get("stickiness_app_cookie_duration")
stickiness_app_cookie_name = module.params.get("stickiness_app_cookie_name")

health_option_keys = [
"health_check_path", "health_check_protocol", "health_check_interval", "health_check_timeout",
Expand Down Expand Up @@ -753,6 +769,12 @@ def create_or_update_target_group(connection, module):
if stickiness_type is not None:
if stickiness_type != current_tg_attributes.get('stickiness_type'):
update_attributes.append({'Key': 'stickiness.type', 'Value': stickiness_type})
if stickiness_app_cookie_name is not None:
if stickiness_app_cookie_name != current_tg_attributes.get('stickiness_app_cookie_name'):
update_attributes.append({'Key': 'stickiness.app_cookie.cookie_name', 'Value': str(stickiness_app_cookie_name)})
if stickiness_app_cookie_duration is not None:
if str(stickiness_app_cookie_duration) != current_tg_attributes['stickiness_app_cookie_duration_seconds']:
update_attributes.append({'Key': 'stickiness.app_cookie.duration_seconds', 'Value': str(stickiness_app_cookie_duration)})

if update_attributes:
try:
Expand Down Expand Up @@ -833,6 +855,8 @@ def main():
stickiness_enabled=dict(type='bool'),
stickiness_type=dict(),
stickiness_lb_cookie_duration=dict(type='int'),
stickiness_app_cookie_duration=dict(type='int'),
stickiness_app_cookie_name=dict(),
state=dict(required=True, choices=['present', 'absent']),
successful_response_codes=dict(),
tags=dict(default={}, type='dict'),
Expand Down