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_route_table: Add IPv6 support in ec2_vpc_route_table #601

Merged
merged 4 commits into from
Jan 13, 2022
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/601-ec2_vpc_route_table-ipv6-support.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- ec2_vpc_route_table - add support for IPv6 in creating route tables (https://github.com/ansible-collections/amazon.aws/pull/601).
11 changes: 8 additions & 3 deletions plugins/modules/ec2_vpc_route_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@

import re
from time import sleep
from ipaddress import ip_network

try:
import botocore
Expand Down Expand Up @@ -408,7 +409,7 @@ def ensure_routes(connection=None, module=None, route_table=None, route_specs=No
for route_spec in route_specs:
match = index_of_matching_route(route_spec, routes_to_match)
if match is None:
if route_spec.get('DestinationCidrBlock'):
if route_spec.get('DestinationCidrBlock') or route_spec.get('DestinationIpv6CidrBlock'):
route_specs_to_create.append(route_spec)
else:
module.warn("Skipping creating {0} because it has no destination cidr block. "
Expand Down Expand Up @@ -588,9 +589,13 @@ def get_route_table_info(connection, module, route_table):

def create_route_spec(connection, module, vpc_id):
routes = module.params.get('routes')

for route_spec in routes:
rename_key(route_spec, 'dest', 'destination_cidr_block')

cidr_block_type = str(type(ip_network(route_spec['dest'])))
if "IPv4" in cidr_block_type:
rename_key(route_spec, 'dest', 'destination_cidr_block')
if "IPv6" in cidr_block_type:
rename_key(route_spec, 'dest', 'destination_ipv6_cidr_block')

if route_spec.get('gateway_id') and route_spec['gateway_id'].lower() == 'igw':
igw = find_igw(connection, module, vpc_id)
Expand Down
16 changes: 10 additions & 6 deletions tests/integration/targets/ec2_vpc_route_table/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@
routes:
- dest: 0.0.0.0/0
gateway_id: igw
- dest: ::/0
gateway_id: igw
check_mode: true
register: check_mode_results
- name: assert a route would be added
Expand All @@ -147,16 +149,18 @@
routes:
- dest: 0.0.0.0/0
gateway_id: igw
- dest: ::/0
gateway_id: igw
register: add_routes
- name: assert route table contains new route
assert:
that:
- add_routes.changed
- add_routes.route_table.routes|length == 2
- add_routes.route_table.routes|length == 3
- add_routes.route_table.id.startswith('rtb-')
- "'Public' in add_routes.route_table.tags and add_routes.route_table.tags['Public']\
\ == 'true'"
- add_routes.route_table.routes|length == 2
- add_routes.route_table.routes|length == 3
- add_routes.route_table.associations|length == 0
- add_routes.route_table.vpc_id == "{{ vpc.vpc.id }}"
- add_routes.route_table.propagating_vgws|length == 0
Expand Down Expand Up @@ -191,7 +195,7 @@
assert:
that:
- add_routes is not changed
- add_routes.route_table.routes|length == 2
- add_routes.route_table.routes|length == 3

- name: CHECK MODE - add subnets to public route table
ec2_vpc_route_table:
Expand Down Expand Up @@ -265,7 +269,7 @@
assert:
that:
- not no_purge_routes.changed
- no_purge_routes.route_table.routes|length == 2
- no_purge_routes.route_table.routes|length == 3
- no_purge_routes.route_table.associations|length == 2

- name: rerun with purge_subnets set to false
Expand All @@ -283,7 +287,7 @@
assert:
that:
- not no_purge_subnets.changed
- no_purge_subnets.route_table.routes|length == 2
- no_purge_subnets.route_table.routes|length == 3
- no_purge_subnets.route_table.associations|length == 2

- name: rerun with purge_tags not set (implicitly false)
Expand Down Expand Up @@ -428,7 +432,7 @@
assert:
that:
- purge_routes.changed
- purge_routes.route_table.routes|length == 1
- purge_routes.route_table.routes|length == 2
- purge_routes.route_table.id == create_public_table.route_table.id

- name: CHECK MODE - update tags
Expand Down