Skip to content

Commit

Permalink
ec2_vpc_route_table: Add IPv6 support in ec2_vpc_route_table (#601)
Browse files Browse the repository at this point in the history
ec2_vpc_route_table: Add IPv6 support in ec2_vpc_route_table

SUMMARY

Allow usage of IPv6 CIDR in ec2_vpc_route_table for creating routes.

Fixes #477
ISSUE TYPE


Feature Pull Request

COMPONENT NAME

ec2_vpc_route_table

Reviewed-by: Jill R <None>
Reviewed-by: None <None>
  • Loading branch information
mandar242 authored Jan 13, 2022
1 parent fe250f2 commit ece90cb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
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

0 comments on commit ece90cb

Please sign in to comment.