diff --git a/moto/ec2/models.py b/moto/ec2/models.py
index 33eaef774..e9e375d26 100644
--- a/moto/ec2/models.py
+++ b/moto/ec2/models.py
@@ -4689,7 +4689,7 @@ class RouteTableBackend(object):
route_table_id,
destination_cidr_block=None,
local=True,
- destination_ipv6_cidr_block=ipv6_cidr,
+ destination_ipv6_cidr_block=ipv6_cidr.get("cidr_block"),
)
return route_table
@@ -4785,6 +4785,7 @@ class Route(CloudFormationModel):
route_table,
destination_cidr_block,
destination_ipv6_cidr_block,
+ prefix_list=None,
local=False,
gateway=None,
instance=None,
@@ -4800,6 +4801,7 @@ class Route(CloudFormationModel):
self.route_table = route_table
self.destination_cidr_block = destination_cidr_block
self.destination_ipv6_cidr_block = destination_ipv6_cidr_block
+ self.prefix_list = prefix_list
self.local = local
self.gateway = gateway
self.instance = instance
@@ -5071,6 +5073,7 @@ class RouteBackend(object):
route_table_id,
destination_cidr_block,
destination_ipv6_cidr_block=None,
+ destination_prefix_list_id=None,
local=False,
gateway_id=None,
instance_id=None,
@@ -5085,6 +5088,7 @@ class RouteBackend(object):
transit_gateway = None
egress_only_igw = None
interface = None
+ prefix_list = None
route_table = self.get_route_table(route_table_id)
@@ -5111,11 +5115,14 @@ class RouteBackend(object):
egress_only_igw = self.get_egress_only_igw(egress_only_igw_id)
if transit_gateway_id is not None:
transit_gateway = self.transit_gateways.get(transit_gateway_id)
+ if destination_prefix_list_id is not None:
+ prefix_list = self.managed_prefix_lists.get(destination_prefix_list_id)
route = Route(
route_table,
destination_cidr_block,
destination_ipv6_cidr_block,
+ prefix_list,
local=local,
gateway=gateway,
instance=self.get_instance(instance_id) if instance_id else None,
@@ -5134,25 +5141,46 @@ class RouteBackend(object):
self,
route_table_id,
destination_cidr_block,
+ destination_ipv6_cidr_block=None,
+ destination_prefix_list_id=None,
+ nat_gateway_id=None,
+ egress_only_igw_id=None,
+ transit_gateway_id=None,
gateway_id=None,
instance_id=None,
interface_id=None,
vpc_peering_connection_id=None,
):
route_table = self.get_route_table(route_table_id)
- route_id = generate_route_id(route_table.id, destination_cidr_block)
+ route_id = generate_route_id(
+ route_table.id, destination_cidr_block, destination_ipv6_cidr_block
+ )
route = route_table.routes[route_id]
if interface_id:
self.raise_not_implemented_error("ReplaceRoute to NetworkInterfaceId")
route.gateway = None
+ route.nat_gateway = None
+ route.egress_only_igw = None
+ route.transit_gateway = None
if gateway_id:
if EC2_RESOURCE_TO_PREFIX["vpn-gateway"] in gateway_id:
route.gateway = self.get_vpn_gateway(gateway_id)
elif EC2_RESOURCE_TO_PREFIX["internet-gateway"] in gateway_id:
route.gateway = self.get_internet_gateway(gateway_id)
+ if nat_gateway_id is not None:
+ route.nat_gateway = self.nat_gateways.get(nat_gateway_id)
+ if egress_only_igw_id is not None:
+ route.egress_only_igw = self.get_egress_only_igw(egress_only_igw_id)
+ if transit_gateway_id is not None:
+ route.transit_gateway = self.transit_gateways.get(transit_gateway_id)
+ if destination_prefix_list_id is not None:
+ route.prefix_list = self.managed_prefix_lists.get(
+ destination_prefix_list_id
+ )
+
route.instance = self.get_instance(instance_id) if instance_id else None
route.interface = None
route.vpc_pcx = (
diff --git a/moto/ec2/responses/route_tables.py b/moto/ec2/responses/route_tables.py
index 137bc92e1..3f4fc6716 100644
--- a/moto/ec2/responses/route_tables.py
+++ b/moto/ec2/responses/route_tables.py
@@ -18,6 +18,7 @@ class RouteTables(BaseResponse):
route_table_id = self._get_param("RouteTableId")
destination_cidr_block = self._get_param("DestinationCidrBlock")
destination_ipv6_cidr_block = self._get_param("DestinationIpv6CidrBlock")
+ destination_prefix_list_id = self._get_param("DestinationPrefixListId")
gateway_id = self._get_param("GatewayId")
instance_id = self._get_param("InstanceId")
nat_gateway_id = self._get_param("NatGatewayId")
@@ -30,6 +31,7 @@ class RouteTables(BaseResponse):
route_table_id,
destination_cidr_block,
destination_ipv6_cidr_block,
+ destination_prefix_list_id,
gateway_id=gateway_id,
instance_id=instance_id,
nat_gateway_id=nat_gateway_id,
@@ -83,14 +85,24 @@ class RouteTables(BaseResponse):
def replace_route(self):
route_table_id = self._get_param("RouteTableId")
destination_cidr_block = self._get_param("DestinationCidrBlock")
+ destination_ipv6_cidr_block = self._get_param("DestinationIpv6CidrBlock")
+ destination_prefix_list_id = self._get_param("DestinationPrefixListId")
gateway_id = self._get_param("GatewayId")
instance_id = self._get_param("InstanceId")
interface_id = self._get_param("NetworkInterfaceId")
pcx_id = self._get_param("VpcPeeringConnectionId")
+ nat_gateway_id = self._get_param("NatGatewayId")
+ egress_only_igw_id = self._get_param("EgressOnlyInternetGatewayId")
+ transit_gateway_id = self._get_param("TransitGatewayId")
self.ec2_backend.replace_route(
route_table_id,
destination_cidr_block,
+ destination_ipv6_cidr_block,
+ destination_prefix_list_id,
+ nat_gateway_id,
+ egress_only_igw_id,
+ transit_gateway_id,
gateway_id=gateway_id,
instance_id=instance_id,
interface_id=interface_id,
@@ -176,13 +188,18 @@ DESCRIBE_ROUTE_TABLES_RESPONSE = """
{% if route.destination_ipv6_cidr_block %}
{{ route.destination_ipv6_cidr_block }}
{% else %}
- {{ route.destination_cidr_block }}
+ {{ route.destination_cidr_block or "" }}
{% endif %}
{% if route.local %}
local
CreateRouteTable
active
{% endif %}
+ {% if route.prefix_list %}
+ {{ route.prefix_list.id }}
+ CreateRoute
+ active
+ {% endif %}
{% if route.gateway %}
{{ route.gateway.id }}
CreateRoute
diff --git a/tests/terraform-tests.success.txt b/tests/terraform-tests.success.txt
index 9d90ca3ed..9fd5a291b 100644
--- a/tests/terraform-tests.success.txt
+++ b/tests/terraform-tests.success.txt
@@ -94,7 +94,6 @@ TestAccAWSUserGroupMembership
TestAccAWSUserPolicyAttachment
TestAccAWSUserSSHKey
TestAccAWSVpc_
-TestAccAWSRouteTable_disappears
TestAccAWSAPIGatewayStage_basic
TestAccAWSAPIGatewayStage_accessLogSettings_kinesis
TestAccAWSAPIGatewayStage_accessLogSettings
@@ -111,6 +110,8 @@ TestAccAWSRouteTable_IPv6_To_EgressOnlyInternetGateway
TestAccAWSRouteTable_IPv6_To_NetworkInterface_Unattached
TestAccAWSRouteTable_disappears
TestAccAWSRouteTable_basic
+TestAccAWSRouteTable_MultipleRoutes
+TestAccAWSRouteTable_PrefixList_To_InternetGateway
TestAccAWSSsmDocumentDataSource
TestAccAwsEc2ManagedPrefixList
TestAccAWSEgressOnlyInternetGateway
diff --git a/tests/test_ec2/test_route_tables.py b/tests/test_ec2/test_route_tables.py
index 7c195235d..8b92b4b4d 100644
--- a/tests/test_ec2/test_route_tables.py
+++ b/tests/test_ec2/test_route_tables.py
@@ -752,9 +752,7 @@ def test_create_route_with_egress_only_igw():
)
route_table.reload()
- eigw_route = [r for r in route_table.routes if r.destination_cidr_block == "None"][
- 0
- ]
+ eigw_route = [r for r in route_table.routes if r.destination_cidr_block == ""][0]
eigw_route.egress_only_internet_gateway_id.should.equal(eigw_id)
eigw_route.state.should.equal("active")