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: fix lost property AvailabilityZone #1767

Merged
Merged
Show file tree
Hide file tree
Changes from 6 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/1736-elb_target_group_property.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- elb_target_group - Property ``AvailabilityZone`` is kept when requested (https://github.com/ansible-collections/community.aws/pull/1767).
tremble marked this conversation as resolved.
Show resolved Hide resolved
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