From c6fa7e18cdbc981738e2b28c5195e5fb0b2548ea Mon Sep 17 00:00:00 2001 From: Taeho Park <113317744+taehopark32@users.noreply.github.com> Date: Tue, 4 Jul 2023 05:17:41 -0400 Subject: [PATCH] ec2_vpc_nat_gateway - changes to no allocate eip address when connectivity_type=private (#1632) ec2_vpc_nat_gateway - changes to no allocate eip address when connectivity_type=private SUMMARY Fixes #1618 ISSUE TYPE Bugfix Pull Request COMPONENT NAME plugins/modules/ec2_vpc_nat_gateway.py ADDITIONAL INFORMATION Reviewed-by: Alina Buzachis (cherry picked from commit afe9ccb52fa0611607c5a8f19f9454cba86980b3) --- ...to-no-allocate-eip-when-connectivity_type=private.yml | 2 ++ plugins/modules/ec2_vpc_nat_gateway.py | 9 ++++----- .../targets/ec2_vpc_nat_gateway/tasks/main.yml | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 changelogs/fragments/1632-changes-to-no-allocate-eip-when-connectivity_type=private.yml diff --git a/changelogs/fragments/1632-changes-to-no-allocate-eip-when-connectivity_type=private.yml b/changelogs/fragments/1632-changes-to-no-allocate-eip-when-connectivity_type=private.yml new file mode 100644 index 00000000000..4b820a3498f --- /dev/null +++ b/changelogs/fragments/1632-changes-to-no-allocate-eip-when-connectivity_type=private.yml @@ -0,0 +1,2 @@ +bugfixes: +- ec2_vpc_nat_gateway - fixes to nat gateway so that when the user creates a private NAT gateway, an Elastic IP address should not be allocated. The module had inncorrectly always allocate elastic IP address when creating private nat gateway (https://github.com/ansible-collections/amazon.aws/pull/1632). \ No newline at end of file diff --git a/plugins/modules/ec2_vpc_nat_gateway.py b/plugins/modules/ec2_vpc_nat_gateway.py index 38bdf34f59d..4b03e5adb52 100644 --- a/plugins/modules/ec2_vpc_nat_gateway.py +++ b/plugins/modules/ec2_vpc_nat_gateway.py @@ -746,12 +746,11 @@ def pre_create(client, module, subnet_id, tags, purge_tags, allocation_id=None, ) return changed, msg, results else: - changed, msg, allocation_id = ( - allocate_eip_address(client, module) - ) + if connectivity_type == "public": + changed, msg, allocation_id = allocate_eip_address(client, module) - if not changed: - return changed, msg, dict() + if not changed: + return changed, msg, dict() elif eip_address or allocation_id: if eip_address and not allocation_id: diff --git a/tests/integration/targets/ec2_vpc_nat_gateway/tasks/main.yml b/tests/integration/targets/ec2_vpc_nat_gateway/tasks/main.yml index 501cccaf9b0..4007d2014a8 100644 --- a/tests/integration/targets/ec2_vpc_nat_gateway/tasks/main.yml +++ b/tests/integration/targets/ec2_vpc_nat_gateway/tasks/main.yml @@ -919,6 +919,7 @@ - create_ngw.changed - create_ngw.connectivity_type == 'private' - '"create_time" in create_ngw' + - '"allocation_id" not in create_ngw.nat_gateway_addresses[0]' - name: 'set facts: NAT gateway ID' set_fact: