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_peer - Fix idempotency when accepter/requester is reversed #1346

Merged
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/580-vpc_peer-idempotency.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- ec2_vpc_peer - fix idempotency when requester/accepter is reversed (https://github.com/ansible-collections/community.aws/issues/580).
5 changes: 5 additions & 0 deletions plugins/modules/ec2_vpc_peer.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@ def describe_peering_connections(params, client):
Filters=ansible_dict_to_boto3_filter_list(peer_filter),
)
if result['VpcPeeringConnections'] == []:
# Try again with the VPC/Peer relationship reversed
peer_filter = {
'requester-vpc-info.vpc-id': params['PeerVpcId'],
'accepter-vpc-info.vpc-id': params['VpcId'],
}
result = client.describe_vpc_peering_connections(
aws_retry=True,
Filters=ansible_dict_to_boto3_filter_list(peer_filter),
Expand Down
43 changes: 34 additions & 9 deletions tests/integration/targets/ec2_vpc_peer/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,22 @@
- vpc_peer is successful
- vpc_peer.peering_id == peer_id_1

- name: (re-) Create local account VPC peering Connection request with accepter/requester reversed (idempotency)
ec2_vpc_peer:
vpc_id: '{{ vpc_2 }}'
peer_vpc_id: '{{ vpc_1 }}'
state: present
tags:
Name: '{{ connection_name }}'
register: vpc_peer

- name: Assert success
assert:
that:
- vpc_peer is not changed
- vpc_peer is successful
- vpc_peer.peering_id == peer_id_1

- name: Get details on specific VPC peer
ec2_vpc_peering_info:
peer_connection_ids:
Expand Down Expand Up @@ -458,21 +474,30 @@
- delete_peer is successful

always:
# ============================================================

- name: delete a local VPC peering Connection
ec2_vpc_peer:
peering_id: "{{ vpc_peer.peering_id }}"
state: absent
register: delete_peer
- name: Find all VPC Peering connections for our VPCs
ec2_vpc_peering_info:
filters:
accepter-vpc-info.vpc-id: '{{ item }}'
register: peering_info
loop:
- '{{ vpc_1 }}'
- '{{ vpc_2 }}'

- set_fact:
vpc_peering_connection_ids: '{{ _vpc_peering_connections | map(attribute="vpc_peering_connection_id") | list }}'
vars:
_vpc_peering_connections: '{{ peering_info.results | map(attribute="vpc_peering_connections") | flatten }}'
ignore_errors: True

- name: delete a local VPC peering Connection
# ============================================================

- name: Delete remaining Peering connections
ec2_vpc_peer:
peering_id: "{{ vpc_peer2.peering_id }}"
peering_id: "{{ item }}"
state: absent
register: delete_peer
ignore_errors: True
loop: '{{ vpc_peering_connection_ids }}'

- name: tidy up VPC 2
ec2_vpc_net:
Expand Down