diff --git a/changelogs/fragments/1800-elb_target_group_property.yml b/changelogs/fragments/1800-elb_target_group_property.yml new file mode 100644 index 00000000000..3c8e2625680 --- /dev/null +++ b/changelogs/fragments/1800-elb_target_group_property.yml @@ -0,0 +1,2 @@ +bugfixes: + - elb_target_group - get ``ProtocolVersion`` key from ``target_group`` attributes only when exists (https://github.com/ansible-collections/community.aws/pull/1800). diff --git a/plugins/modules/elb_target_group.py b/plugins/modules/elb_target_group.py index 854876e0710..45a6e7ae965 100644 --- a/plugins/modules/elb_target_group.py +++ b/plugins/modules/elb_target_group.py @@ -680,12 +680,12 @@ def create_or_update_target_group(connection, module): # Matcher (successful response codes) # TODO: required and here? - if 'Matcher' in params: - 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 "Matcher" in params: + code_key = "HttpCode" + if target_group.get("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'][code_key] = ','.join(requested_matcher_list)