From 42c428dd9d4d39ce57ece50606a26b554f373543 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Tue, 28 Dec 2021 05:09:53 -0800 Subject: [PATCH 1/4] Add IPv6 support in ec2_vpc_route_table --- plugins/modules/ec2_vpc_route_table.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/plugins/modules/ec2_vpc_route_table.py b/plugins/modules/ec2_vpc_route_table.py index fa4005eb521..55f362194e3 100644 --- a/plugins/modules/ec2_vpc_route_table.py +++ b/plugins/modules/ec2_vpc_route_table.py @@ -226,6 +226,7 @@ import re from time import sleep +from ipaddress import ip_network try: import botocore @@ -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. " @@ -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) From 5bb2f49e16d0a41fb172cb673113ab069cc03899 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Tue, 28 Dec 2021 06:31:35 -0800 Subject: [PATCH 2/4] Modify Integration tests to test usage of IPv6 CIDR --- .../targets/ec2_vpc_route_table/tasks/main.yml | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/integration/targets/ec2_vpc_route_table/tasks/main.yml b/tests/integration/targets/ec2_vpc_route_table/tasks/main.yml index 2095c589163..f161ce24ab1 100644 --- a/tests/integration/targets/ec2_vpc_route_table/tasks/main.yml +++ b/tests/integration/targets/ec2_vpc_route_table/tasks/main.yml @@ -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 @@ -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 @@ -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: @@ -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 @@ -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) @@ -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 From 9c4c4731801bce6dafae04aa383b3b6d5da260f2 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Tue, 4 Jan 2022 07:23:13 -0800 Subject: [PATCH 3/4] Add changelogs fragment --- changelogs/fragments/601-ec2_vpc_route_table-ipv6-support.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/601-ec2_vpc_route_table-ipv6-support.yml diff --git a/changelogs/fragments/601-ec2_vpc_route_table-ipv6-support.yml b/changelogs/fragments/601-ec2_vpc_route_table-ipv6-support.yml new file mode 100644 index 00000000000..a64053ea130 --- /dev/null +++ b/changelogs/fragments/601-ec2_vpc_route_table-ipv6-support.yml @@ -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). \ No newline at end of file From 4733b0bf3fdbad2b95ca8242b8bc3ac7a5a36225 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Tue, 4 Jan 2022 07:34:33 -0800 Subject: [PATCH 4/4] Minor: Add newline at EOF --- changelogs/fragments/601-ec2_vpc_route_table-ipv6-support.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelogs/fragments/601-ec2_vpc_route_table-ipv6-support.yml b/changelogs/fragments/601-ec2_vpc_route_table-ipv6-support.yml index a64053ea130..59a286c7041 100644 --- a/changelogs/fragments/601-ec2_vpc_route_table-ipv6-support.yml +++ b/changelogs/fragments/601-ec2_vpc_route_table-ipv6-support.yml @@ -1,2 +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). \ No newline at end of file +- ec2_vpc_route_table - add support for IPv6 in creating route tables (https://github.com/ansible-collections/amazon.aws/pull/601).