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

ec2_vpc_nat_gateway show fails if EIP doesn't exist #1604

Merged
Prev Previous commit
Next Next commit
changes to the test cases and add documentation
  • Loading branch information
taehopark32 committed Jun 15, 2023
commit 9f283226d39ec2be1c32e8f4026d61c0363b9277
9 changes: 8 additions & 1 deletion plugins/modules/ec2_vpc_nat_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@
When specifying this option, ensure you specify the eip_address parameter
as well otherwise any subsequent runs will fail.
type: str
default_create:
description:
- if EIP address is not found, create NAT gateway with EIP address as null.
Copy link
Collaborator

@alinabuzachis alinabuzachis Jun 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the description of this parameter must be carified. What happens when the users specifies an invalid allocation_id? Does default_create: True allow to still create the NAT gateway and allocate a new EIP?

Something like this:

  • When I(default_create=True), if I(eip_address) is set and it is invalid or does not exist, the NAT gateway is successfully created and a new EIP is automatically allocated.
  • When I(default_create=True), if I(allocation_id) is set and it is invalid or not found, the NAT gateway is successfully created and a new EIP is automatically allocated. (If this is true!!!)
  • When I(default_create=False), what happens?

Please feel free to rephrase and correct my suggestions.

default = true
type: bool
taehopark32 marked this conversation as resolved.
Show resolved Hide resolved
author:
- Allen Sanabria (@linuxdynasty)
- Jon Hadfield (@jonhadfield)
Expand Down Expand Up @@ -682,6 +687,8 @@ def pre_create(
default = False
client_token (str):
default = None
default_create (bool): create a NAT gateway even if EIP address is not found.
default = False

Basic Usage:
>>> client = boto3.client('ec2')
Expand Down Expand Up @@ -886,7 +893,7 @@ def main():
client_token=dict(type="str", no_log=False),
tags=dict(required=False, type="dict", aliases=["resource_tags"]),
purge_tags=dict(default=True, type="bool"),
default_create=dict(type="str"),
default_create=dict(type="bool", default=False),
)

module = AnsibleAWSModule(
Expand Down
25 changes: 1 addition & 24 deletions tests/integration/targets/ec2_vpc_nat_gateway/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -411,33 +411,11 @@
- create_ngw.vpc_id == vpc_id


# ============================================================
- name: Allocate a new EIP
ec2_eip:
in_vpc: true
reuse_existing_ip_allowed: true
tag_name: FREE
register: eip_result

- name: Assert success
assert:
that:
- eip_result is successful
- '"allocation_id" in eip_result'
- eip_result.allocation_id.startswith("eipalloc-")
- '"public_ip" in eip_result'

- name: 'Set fact: EIP allocation ID and EIP public IP'
set_fact:
third_eip_address: '{{ eip_result.public_ip }}'
third_allocation_id: '{{ eip_result.allocation_id }}'


# ============================================================
- name: Create new NAT gateway when eip_address is invalid and create_default is true
ec2_vpc_nat_gateway:
subnet_id: '{{ subnet_id }}'
eip_address: "{{ third_eip_address }}"
eip_address: "192.0.2.1"
state: present
wait: yes
default_create: true
Expand All @@ -450,7 +428,6 @@
- '"create_time" in _nat_gateway'
- '"nat_gateway_addresses" in _nat_gateway'
- '"nat_gateway_id" in _nat_gateway'
- _nat_gateway.nat_gateway_addresses[0].allocation_id == third_allocation_id
- _nat_gateway.nat_gateway_id.startswith("nat-")
- '"state" in _nat_gateway'
- _nat_gateway.state == 'available'
Expand Down