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

elb_target_group: Add support for protocol_version parameter #1496

Merged
Show file tree
Hide file tree
Changes from 14 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,2 @@
minor_changes:
- elb_target_group - add support for ``protocol_version`` parameter (https://github.com/ansible-collections/community.aws/pull/1496).
34 changes: 30 additions & 4 deletions plugins/modules/elb_target_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@
required: false
choices: [ 'http', 'https', 'tcp', 'tls', 'udp', 'tcp_udp', 'HTTP', 'HTTPS', 'TCP', 'TLS', 'UDP', 'TCP_UDP']
type: str
protocol_version:
description:
- Specifies protocol version.
required: false
choices: ['GRPC', 'HTTP1', 'HTTP2']
type: str
markuman marked this conversation as resolved.
Show resolved Hide resolved
version_added: 5.1.0
state:
description:
- Create or destroy the target group.
Expand Down Expand Up @@ -216,6 +223,15 @@
vpc_id: vpc-01234567
state: present

- name: Create a target group with protocol_version 'GRPC'
community.aws.elb_target_group:
name: mytargetgroup
protocol: http
port: 80
vpc_id: vpc-01234567
protocol_version: GRPC
state: present

- name: Modify the target group with a custom health check
community.aws.elb_target_group:
name: mytargetgroup
Expand Down Expand Up @@ -566,6 +582,8 @@ def create_or_update_target_group(connection, module):
params['TargetType'] = target_type
if target_type != "lambda":
params['Protocol'] = module.params.get("protocol").upper()
if module.params.get('protocol_version') is not None:
params['ProtocolVersion'] = module.params.get('protocol_version')
params['Port'] = module.params.get("port")
params['VpcId'] = module.params.get("vpc_id")
tags = module.params.get("tags")
Expand Down Expand Up @@ -607,7 +625,11 @@ def create_or_update_target_group(connection, module):

if module.params.get("successful_response_codes") is not None:
params['Matcher'] = {}
params['Matcher']['HttpCode'] = module.params.get("successful_response_codes")
code_key = 'HttpCode'
protocol_version = module.params.get('protocol_version')
if protocol_version is not None and protocol_version.upper() == "GRPC":
code_key = 'GrpcCode'
params['Matcher'][code_key] = module.params.get("successful_response_codes")

# Get target group
target_group = get_target_group(connection, module)
Expand Down Expand Up @@ -657,11 +679,14 @@ def create_or_update_target_group(connection, module):
# Matcher (successful response codes)
# TODO: required and here?
if 'Matcher' in params:
current_matcher_list = target_group['Matcher']['HttpCode'].split(',')
requested_matcher_list = params['Matcher']['HttpCode'].split(',')
code_key = 'HttpCode'
if target_group['ProtocolVersion'] == 'GRPC':
code_key = 'GrpcCode'
current_matcher_list = target_group['Matcher'][code_key].split(',')
requested_matcher_list = params['Matcher'][code_key].split(',')
if set(current_matcher_list) != set(requested_matcher_list):
health_check_params['Matcher'] = {}
health_check_params['Matcher']['HttpCode'] = ','.join(requested_matcher_list)
health_check_params['Matcher'][code_key] = ','.join(requested_matcher_list)

try:
if health_check_params:
Expand Down Expand Up @@ -912,6 +937,7 @@ def main():
name=dict(required=True),
port=dict(type='int'),
protocol=dict(choices=protocols_list),
protocol_version=dict(type='str', choices=['GRPC', 'HTTP1', 'HTTP2']),
purge_tags=dict(default=True, type='bool'),
stickiness_enabled=dict(type='bool'),
stickiness_type=dict(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
- name: Run elb_target_group protocol_version tests
block:

# =====================================================================
- name: set up testing VPC
ec2_vpc_net:
name: "{{ resource_prefix }}-etg-protocol-version-vpc"
state: present
cidr_block: 20.0.0.0/16
tags:
Name: "{{ resource_prefix }}-etg-protocol-version-vpc"
Description: "Created by ansible-test"
register: vpc

# =====================================================================
- name: Create a target group with protocol_version 'GRPC'
community.aws.elb_target_group:
name: "{{ elb_target_group_name }}"
protocol: http
port: 80
vpc_id: "{{ vpc.vpc.id }}"
protocol_version: GRPC
state: present
register: create_result

- assert:
that:
- create_result is changed
- create_result is not failed
- create_result.protocol_version == "GRPC"
- create_result.protocol == "HTTP"
- create_result.port == 80

- name: Create a target group with protocol_version 'GRPC' (idempotence)
community.aws.elb_target_group:
name: "{{ elb_target_group_name }}"
protocol: http
port: 80
vpc_id: "{{ vpc.vpc.id }}"
protocol_version: GRPC
state: present
register: create_result

- assert:
that:
- create_result is not changed
- create_result is not failed
- create_result.protocol_version == "GRPC"
- create_result.protocol == "HTTP"
- create_result.port == 80
Comment on lines +35 to +51
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sharvarikhedkar can you also please a third test that verify that a change of the protocol_version works properly?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...otherwise LGTM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @markuman, I tried testing the code for updating the target group with different protocol_versions but looking at the boto3 documentation and trying to modify protocol_version through AWS console, it seems like the update operation for protocol_version parameter is not supported yet, any insights on this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't know that. Maybe that should be mentioned than in the module documentation @sharvarikhedkar

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.


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

always:
- name: Remove elb target group
elb_target_group:
name: "{{ elb_target_group_name }}"
state: absent
ignore_errors: true
register: deletion_result

- name: remove testing VPC
ec2_vpc_net:
name: "{{ resource_prefix }}-etg-protocol-version-vpc"
cidr_block: 20.0.0.0/16
state: absent
register: removed
retries: 10
until: removed is not failed
ignore_errors: true

- name: Ensure elb_target_group deletion
assert:
that:
- deletion_result is changed
- deletion_result is not failed
1 change: 1 addition & 0 deletions tests/integration/targets/elb_target/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- community.general
- amazon.aws
block:
- include_tasks: etg_protocol_version.yml
- include_tasks: ec2_target.yml
- include_tasks: lambda_target.yml
- include_tasks: alb_target.yml