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

Fix EIP allocation with in_vpc not set #731

Merged
merged 4 commits into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all 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/731-ec2_eip-not_in_vpc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- ec2_eip - fix bug when allocating an EIP but not associating it to a VPC (https://github.com/ansible-collections/community.aws/pull/731).
5 changes: 3 additions & 2 deletions plugins/modules/ec2_eip.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,11 @@ def address_is_associated_with_device(ec2, module, address, device_id, is_instan

def allocate_address(ec2, module, domain, reuse_existing_ip_allowed, check_mode, tag_dict=None, public_ipv4_pool=None):
""" Allocate a new elastic IP address (when needed) and return it """
if not domain:
domain = 'standard'

if reuse_existing_ip_allowed:
filters = []
if not domain:
domain = 'standard'
filters.append({'Name': 'domain', "Values": [domain]})

if tag_dict is not None:
Expand Down
25 changes: 25 additions & 0 deletions tests/integration/targets/ec2_eip/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,25 @@
state: absent
name: '{{ resource_prefix }}-vpc'
cidr_block: '{{ vpc_cidr }}'

- name: Create an EIP outside a VPC
ec2_eip:
state: present
in_vpc: '{{ omit }}'
register: unbound_eip
- assert:
that:
- unbound_eip is successful
- unbound_eip is changed
- name: Release EIP
ec2_eip:
state: absent
public_ip: '{{ unbound_eip.public_ip }}'
register: release_unbound_eip
- assert:
that:
- release_unbound_eip is successful
- release_unbound_eip is changed
# =====================================================
always:
- name: Cleanup instance (by id)
Expand Down Expand Up @@ -735,6 +754,12 @@
public_ip: '{{ no_tagged_eip.public_ip }}'
when: no_tagged_eip is changed
ignore_errors: true
- name: Cleanup unbound_eip
ec2_eip:
state: absent
public_ip: '{{ unbound_eip.public_ip }}'
when: unbound_eip is changed
ignore_errors: true
- name: Cleanup VPC
ec2_vpc_net:
state: absent
Expand Down