From d9c0c1f2ae4c3632cb6fbf3d786181df33ab63e4 Mon Sep 17 00:00:00 2001 From: Phoosha Date: Tue, 15 Dec 2020 21:21:39 +0100 Subject: [PATCH] Fix eip association when both instance id and private ip address are passed (#328) * Fix ec2_eip with both instance_id and private_ip_address * Add changelog fragment for the ec2_eip fix --- ...ix-ec2_eip-instance-id-private-ip-address.yml | 2 ++ plugins/modules/ec2_eip.py | 2 +- tests/integration/targets/ec2_eip/tasks/main.yml | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/328-fix-ec2_eip-instance-id-private-ip-address.yml diff --git a/changelogs/fragments/328-fix-ec2_eip-instance-id-private-ip-address.yml b/changelogs/fragments/328-fix-ec2_eip-instance-id-private-ip-address.yml new file mode 100644 index 00000000000..8701cdd8694 --- /dev/null +++ b/changelogs/fragments/328-fix-ec2_eip-instance-id-private-ip-address.yml @@ -0,0 +1,2 @@ +bugfixes: + - ec2_eip - fix eip association by instance id & private ip address due to case-sensitivity of the ``PrivateIpAddress`` parameter (https://github.com/ansible-collections/community.aws/pull/328). diff --git a/plugins/modules/ec2_eip.py b/plugins/modules/ec2_eip.py index 6aa2a531069..54624f59182 100644 --- a/plugins/modules/ec2_eip.py +++ b/plugins/modules/ec2_eip.py @@ -241,7 +241,7 @@ def associate_ip_and_device(ec2, module, address, private_ip_address, device_id, AllowReassociation=allow_reassociation, ) if private_ip_address: - params['PrivateIPAddress'] = private_ip_address + params['PrivateIpAddress'] = private_ip_address if address['Domain'] == 'vpc': params['AllocationId'] = address['AllocationId'] else: diff --git a/tests/integration/targets/ec2_eip/tasks/main.yml b/tests/integration/targets/ec2_eip/tasks/main.yml index 6d904003012..83093572697 100644 --- a/tests/integration/targets/ec2_eip/tasks/main.yml +++ b/tests/integration/targets/ec2_eip/tasks/main.yml @@ -571,6 +571,22 @@ - instance_eip is success - eip_info.addresses[0].allocation_id is defined - eip_info.addresses[0].instance_id == '{{ instance_info.instances[0].instance_id }}' + - name: Attach eip to an EC2 instance with private Ip specified + ec2_eip: + device_id: '{{ instance_info.instances[0].instance_id }}' + private_ip_address: '{{ instance_info.instances[0].private_ip_address }}' + state: present + release_on_disassociation: yes + register: instance_eip + - ec2_eip_info: + filters: + public-ip: '{{ instance_eip.public_ip }}' + register: eip_info + - assert: + that: + - instance_eip is success + - eip_info.addresses[0].allocation_id is defined + - eip_info.addresses[0].instance_id == '{{ instance_info.instances[0].instance_id }}' # ===================================================== - name: Cleanup instance ec2_instance: