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..59a286c7041 --- /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). 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) 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