Skip to content

Commit

Permalink
elb_target_group: fix lost property AvailabilityZone (#1767) (#1776)
Browse files Browse the repository at this point in the history
[PR #1767/d8362a0e backport][stable-5] elb_target_group: fix lost property AvailabilityZone

This is a backport of PR #1767 as merged into main (d8362a0).
SUMMARY
Closes #1736
ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME
elb_target_group

Reviewed-by: Markus Bergholz <[email protected]>
  • Loading branch information
patchback[bot] authored Apr 18, 2023
1 parent 63920a1 commit 7755165
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 11 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/1736-elb_target_group_property.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- elb_target_group - ensure ``AvailabilityZone`` is kept in target definitions when ``Id`` and ``Port`` are passed (https://github.com/ansible-collections/community.aws/issues/1736).
9 changes: 6 additions & 3 deletions plugins/modules/elb_target_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,9 +729,12 @@ def create_or_update_target_group(connection, module):

if add_instances:
instances_to_add = []
for target in params['Targets']:
if target['Id'] in add_instances:
instances_to_add.append({'Id': target['Id'], 'Port': target['Port']})
for target in params["Targets"]:
if target["Id"] in add_instances:
tmp_item = {"Id": target["Id"], "Port": target["Port"]}
if target.get("AvailabilityZone"):
tmp_item["AvailabilityZone"] = target["AvailabilityZone"]
instances_to_add.append(tmp_item)

changed = True
try:
Expand Down
51 changes: 43 additions & 8 deletions tests/integration/targets/elb_target/tasks/ec2_target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,8 @@
tags:
Name: "{{ resource_prefix }}-inst"
user_data: |
#cloud-config
package_upgrade: true
package_update: true
packages:
- httpd
runcmd:
- "service httpd start"
- echo "HELLO ANSIBLE" > /var/www/html/index.html
#!/bin/bash
sudo nohup python3 -m http.server 80 &
register: ec2

- set_fact:
Expand Down Expand Up @@ -480,6 +474,46 @@
- not result.changed
- not result.target_health_descriptions

- name: create ip target group
elb_target_group:
name: "{{ tg_name }}-ip"
health_check_port: 443
protocol: tcp
port: 443
vpc_id: "{{ vpc.vpc.id }}"
state: present
target_type: ip
register: result

- name: ip target group must be created
assert:
that:
- result.changed
- result.target_type == 'ip'

- name: "mobify ip target group with AvailabilityZone: all"
elb_target_group:
name: "{{ tg_name }}-ip"
health_check_port: 443
protocol: tcp
port: 443
vpc_id: "{{ vpc.vpc.id }}"
state: present
target_type: ip
wait: false
modify_targets: true
targets:
- Id: 192.168.178.32
Port: 443
AvailabilityZone: all
register: result

- name: ip target group must be modified
assert:
that:
- result.changed
- result.load_balancing_cross_zone_enabled == 'use_load_balancer_configuration'

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

always:
Expand Down Expand Up @@ -533,6 +567,7 @@
- "{{ tg_used_name }}"
- "{{ tg_tcpudp_name }}"
- "{{ tg_name }}-nlb"
- "{{ tg_name }}-ip"
ignore_errors: true

- name: remove routing rules
Expand Down

0 comments on commit 7755165

Please sign in to comment.