Skip to content

Commit

Permalink
elb_target_group: Add support for protocol_version parameter (#1496) (#…
Browse files Browse the repository at this point in the history
…1577)

[PR #1496/02bbc544 backport][stable-5] elb_target_group: Add support for protocol_version parameter

This is a backport of PR #1496 as merged into main (02bbc54).
SUMMARY
Added support for protocol_version param in elb_target_group.
Fixes 1422.
ISSUE TYPE


Feature Pull Request

COMPONENT NAME
elb_target_group

Reviewed-by: Markus Bergholz <[email protected]>
  • Loading branch information
patchback[bot] authored Nov 15, 2022
1 parent 660c4f2 commit 311a7c2
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 4 deletions.
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).
35 changes: 31 additions & 4 deletions plugins/modules/elb_target_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@
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.
- The protocol_version parameter is immutable and cannot be changed when updating an elb_target_group.
required: false
choices: ['GRPC', 'HTTP1', 'HTTP2']
type: str
version_added: 5.1.0
state:
description:
- Create or destroy the target group.
Expand Down Expand Up @@ -217,6 +225,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 @@ -567,6 +584,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 @@ -608,7 +627,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 @@ -658,11 +681,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 @@ -913,6 +939,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

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

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

0 comments on commit 311a7c2

Please sign in to comment.