added support for prefix-list; improved support for replace route (#4273)
This commit is contained in:
parent
eef21767f8
commit
3885e20298
@ -4689,7 +4689,7 @@ class RouteTableBackend(object):
|
|||||||
route_table_id,
|
route_table_id,
|
||||||
destination_cidr_block=None,
|
destination_cidr_block=None,
|
||||||
local=True,
|
local=True,
|
||||||
destination_ipv6_cidr_block=ipv6_cidr,
|
destination_ipv6_cidr_block=ipv6_cidr.get("cidr_block"),
|
||||||
)
|
)
|
||||||
|
|
||||||
return route_table
|
return route_table
|
||||||
@ -4785,6 +4785,7 @@ class Route(CloudFormationModel):
|
|||||||
route_table,
|
route_table,
|
||||||
destination_cidr_block,
|
destination_cidr_block,
|
||||||
destination_ipv6_cidr_block,
|
destination_ipv6_cidr_block,
|
||||||
|
prefix_list=None,
|
||||||
local=False,
|
local=False,
|
||||||
gateway=None,
|
gateway=None,
|
||||||
instance=None,
|
instance=None,
|
||||||
@ -4800,6 +4801,7 @@ class Route(CloudFormationModel):
|
|||||||
self.route_table = route_table
|
self.route_table = route_table
|
||||||
self.destination_cidr_block = destination_cidr_block
|
self.destination_cidr_block = destination_cidr_block
|
||||||
self.destination_ipv6_cidr_block = destination_ipv6_cidr_block
|
self.destination_ipv6_cidr_block = destination_ipv6_cidr_block
|
||||||
|
self.prefix_list = prefix_list
|
||||||
self.local = local
|
self.local = local
|
||||||
self.gateway = gateway
|
self.gateway = gateway
|
||||||
self.instance = instance
|
self.instance = instance
|
||||||
@ -5071,6 +5073,7 @@ class RouteBackend(object):
|
|||||||
route_table_id,
|
route_table_id,
|
||||||
destination_cidr_block,
|
destination_cidr_block,
|
||||||
destination_ipv6_cidr_block=None,
|
destination_ipv6_cidr_block=None,
|
||||||
|
destination_prefix_list_id=None,
|
||||||
local=False,
|
local=False,
|
||||||
gateway_id=None,
|
gateway_id=None,
|
||||||
instance_id=None,
|
instance_id=None,
|
||||||
@ -5085,6 +5088,7 @@ class RouteBackend(object):
|
|||||||
transit_gateway = None
|
transit_gateway = None
|
||||||
egress_only_igw = None
|
egress_only_igw = None
|
||||||
interface = None
|
interface = None
|
||||||
|
prefix_list = None
|
||||||
|
|
||||||
route_table = self.get_route_table(route_table_id)
|
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)
|
egress_only_igw = self.get_egress_only_igw(egress_only_igw_id)
|
||||||
if transit_gateway_id is not None:
|
if transit_gateway_id is not None:
|
||||||
transit_gateway = self.transit_gateways.get(transit_gateway_id)
|
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 = Route(
|
||||||
route_table,
|
route_table,
|
||||||
destination_cidr_block,
|
destination_cidr_block,
|
||||||
destination_ipv6_cidr_block,
|
destination_ipv6_cidr_block,
|
||||||
|
prefix_list,
|
||||||
local=local,
|
local=local,
|
||||||
gateway=gateway,
|
gateway=gateway,
|
||||||
instance=self.get_instance(instance_id) if instance_id else None,
|
instance=self.get_instance(instance_id) if instance_id else None,
|
||||||
@ -5134,25 +5141,46 @@ class RouteBackend(object):
|
|||||||
self,
|
self,
|
||||||
route_table_id,
|
route_table_id,
|
||||||
destination_cidr_block,
|
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,
|
gateway_id=None,
|
||||||
instance_id=None,
|
instance_id=None,
|
||||||
interface_id=None,
|
interface_id=None,
|
||||||
vpc_peering_connection_id=None,
|
vpc_peering_connection_id=None,
|
||||||
):
|
):
|
||||||
route_table = self.get_route_table(route_table_id)
|
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]
|
route = route_table.routes[route_id]
|
||||||
|
|
||||||
if interface_id:
|
if interface_id:
|
||||||
self.raise_not_implemented_error("ReplaceRoute to NetworkInterfaceId")
|
self.raise_not_implemented_error("ReplaceRoute to NetworkInterfaceId")
|
||||||
|
|
||||||
route.gateway = None
|
route.gateway = None
|
||||||
|
route.nat_gateway = None
|
||||||
|
route.egress_only_igw = None
|
||||||
|
route.transit_gateway = None
|
||||||
if gateway_id:
|
if gateway_id:
|
||||||
if EC2_RESOURCE_TO_PREFIX["vpn-gateway"] in gateway_id:
|
if EC2_RESOURCE_TO_PREFIX["vpn-gateway"] in gateway_id:
|
||||||
route.gateway = self.get_vpn_gateway(gateway_id)
|
route.gateway = self.get_vpn_gateway(gateway_id)
|
||||||
elif EC2_RESOURCE_TO_PREFIX["internet-gateway"] in gateway_id:
|
elif EC2_RESOURCE_TO_PREFIX["internet-gateway"] in gateway_id:
|
||||||
route.gateway = self.get_internet_gateway(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.instance = self.get_instance(instance_id) if instance_id else None
|
||||||
route.interface = None
|
route.interface = None
|
||||||
route.vpc_pcx = (
|
route.vpc_pcx = (
|
||||||
|
@ -18,6 +18,7 @@ class RouteTables(BaseResponse):
|
|||||||
route_table_id = self._get_param("RouteTableId")
|
route_table_id = self._get_param("RouteTableId")
|
||||||
destination_cidr_block = self._get_param("DestinationCidrBlock")
|
destination_cidr_block = self._get_param("DestinationCidrBlock")
|
||||||
destination_ipv6_cidr_block = self._get_param("DestinationIpv6CidrBlock")
|
destination_ipv6_cidr_block = self._get_param("DestinationIpv6CidrBlock")
|
||||||
|
destination_prefix_list_id = self._get_param("DestinationPrefixListId")
|
||||||
gateway_id = self._get_param("GatewayId")
|
gateway_id = self._get_param("GatewayId")
|
||||||
instance_id = self._get_param("InstanceId")
|
instance_id = self._get_param("InstanceId")
|
||||||
nat_gateway_id = self._get_param("NatGatewayId")
|
nat_gateway_id = self._get_param("NatGatewayId")
|
||||||
@ -30,6 +31,7 @@ class RouteTables(BaseResponse):
|
|||||||
route_table_id,
|
route_table_id,
|
||||||
destination_cidr_block,
|
destination_cidr_block,
|
||||||
destination_ipv6_cidr_block,
|
destination_ipv6_cidr_block,
|
||||||
|
destination_prefix_list_id,
|
||||||
gateway_id=gateway_id,
|
gateway_id=gateway_id,
|
||||||
instance_id=instance_id,
|
instance_id=instance_id,
|
||||||
nat_gateway_id=nat_gateway_id,
|
nat_gateway_id=nat_gateway_id,
|
||||||
@ -83,14 +85,24 @@ class RouteTables(BaseResponse):
|
|||||||
def replace_route(self):
|
def replace_route(self):
|
||||||
route_table_id = self._get_param("RouteTableId")
|
route_table_id = self._get_param("RouteTableId")
|
||||||
destination_cidr_block = self._get_param("DestinationCidrBlock")
|
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")
|
gateway_id = self._get_param("GatewayId")
|
||||||
instance_id = self._get_param("InstanceId")
|
instance_id = self._get_param("InstanceId")
|
||||||
interface_id = self._get_param("NetworkInterfaceId")
|
interface_id = self._get_param("NetworkInterfaceId")
|
||||||
pcx_id = self._get_param("VpcPeeringConnectionId")
|
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(
|
self.ec2_backend.replace_route(
|
||||||
route_table_id,
|
route_table_id,
|
||||||
destination_cidr_block,
|
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,
|
gateway_id=gateway_id,
|
||||||
instance_id=instance_id,
|
instance_id=instance_id,
|
||||||
interface_id=interface_id,
|
interface_id=interface_id,
|
||||||
@ -176,13 +188,18 @@ DESCRIBE_ROUTE_TABLES_RESPONSE = """
|
|||||||
{% if route.destination_ipv6_cidr_block %}
|
{% if route.destination_ipv6_cidr_block %}
|
||||||
<destinationIpv6CidrBlock>{{ route.destination_ipv6_cidr_block }}</destinationIpv6CidrBlock>
|
<destinationIpv6CidrBlock>{{ route.destination_ipv6_cidr_block }}</destinationIpv6CidrBlock>
|
||||||
{% else %}
|
{% else %}
|
||||||
<destinationCidrBlock>{{ route.destination_cidr_block }}</destinationCidrBlock>
|
<destinationCidrBlock>{{ route.destination_cidr_block or "" }}</destinationCidrBlock>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if route.local %}
|
{% if route.local %}
|
||||||
<gatewayId>local</gatewayId>
|
<gatewayId>local</gatewayId>
|
||||||
<origin>CreateRouteTable</origin>
|
<origin>CreateRouteTable</origin>
|
||||||
<state>active</state>
|
<state>active</state>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if route.prefix_list %}
|
||||||
|
<destinationPrefixListId>{{ route.prefix_list.id }}</destinationPrefixListId>
|
||||||
|
<origin>CreateRoute</origin>
|
||||||
|
<state>active</state>
|
||||||
|
{% endif %}
|
||||||
{% if route.gateway %}
|
{% if route.gateway %}
|
||||||
<gatewayId>{{ route.gateway.id }}</gatewayId>
|
<gatewayId>{{ route.gateway.id }}</gatewayId>
|
||||||
<origin>CreateRoute</origin>
|
<origin>CreateRoute</origin>
|
||||||
|
@ -94,7 +94,6 @@ TestAccAWSUserGroupMembership
|
|||||||
TestAccAWSUserPolicyAttachment
|
TestAccAWSUserPolicyAttachment
|
||||||
TestAccAWSUserSSHKey
|
TestAccAWSUserSSHKey
|
||||||
TestAccAWSVpc_
|
TestAccAWSVpc_
|
||||||
TestAccAWSRouteTable_disappears
|
|
||||||
TestAccAWSAPIGatewayStage_basic
|
TestAccAWSAPIGatewayStage_basic
|
||||||
TestAccAWSAPIGatewayStage_accessLogSettings_kinesis
|
TestAccAWSAPIGatewayStage_accessLogSettings_kinesis
|
||||||
TestAccAWSAPIGatewayStage_accessLogSettings
|
TestAccAWSAPIGatewayStage_accessLogSettings
|
||||||
@ -111,6 +110,8 @@ TestAccAWSRouteTable_IPv6_To_EgressOnlyInternetGateway
|
|||||||
TestAccAWSRouteTable_IPv6_To_NetworkInterface_Unattached
|
TestAccAWSRouteTable_IPv6_To_NetworkInterface_Unattached
|
||||||
TestAccAWSRouteTable_disappears
|
TestAccAWSRouteTable_disappears
|
||||||
TestAccAWSRouteTable_basic
|
TestAccAWSRouteTable_basic
|
||||||
|
TestAccAWSRouteTable_MultipleRoutes
|
||||||
|
TestAccAWSRouteTable_PrefixList_To_InternetGateway
|
||||||
TestAccAWSSsmDocumentDataSource
|
TestAccAWSSsmDocumentDataSource
|
||||||
TestAccAwsEc2ManagedPrefixList
|
TestAccAwsEc2ManagedPrefixList
|
||||||
TestAccAWSEgressOnlyInternetGateway
|
TestAccAWSEgressOnlyInternetGateway
|
||||||
|
@ -752,9 +752,7 @@ def test_create_route_with_egress_only_igw():
|
|||||||
)
|
)
|
||||||
|
|
||||||
route_table.reload()
|
route_table.reload()
|
||||||
eigw_route = [r for r in route_table.routes if r.destination_cidr_block == "None"][
|
eigw_route = [r for r in route_table.routes if r.destination_cidr_block == ""][0]
|
||||||
0
|
|
||||||
]
|
|
||||||
eigw_route.egress_only_internet_gateway_id.should.equal(eigw_id)
|
eigw_route.egress_only_internet_gateway_id.should.equal(eigw_id)
|
||||||
eigw_route.state.should.equal("active")
|
eigw_route.state.should.equal("active")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user