EC2 - Cross region VPC peering bug (#4764)

This commit is contained in:
Bert Blommers 2022-01-15 12:00:19 -01:00 committed by GitHub
parent f45da41b33
commit 8f63ce073e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 17 deletions

View File

@ -3919,13 +3919,6 @@ class VPCBackend(object):
self.vpc_refs[self.__class__].add(weakref.ref(self))
super().__init__()
@classmethod
def get_vpc_refs(cls):
for inst_ref in cls.vpc_refs[cls]:
inst = inst_ref()
if inst is not None:
yield inst
def create_vpc(
self,
cidr_block,
@ -3975,13 +3968,6 @@ class VPCBackend(object):
raise InvalidVPCIdError(vpc_id)
return self.vpcs.get(vpc_id)
# get vpc by vpc id and aws region
def get_cross_vpc(self, vpc_id, peer_region):
for vpcs in self.get_vpc_refs():
if vpcs.region_name == peer_region:
match_vpc = vpcs.get_vpc(vpc_id)
return match_vpc
def describe_vpcs(self, vpc_ids=None, filters=None):
matches = self.vpcs.copy().values()
if vpc_ids:

View File

@ -13,9 +13,9 @@ class VPCPeeringConnections(BaseResponse):
if peer_region == self.region or peer_region is None:
peer_vpc = self.ec2_backend.get_vpc(self._get_param("PeerVpcId"))
else:
peer_vpc = self.ec2_backend.get_cross_vpc(
self._get_param("PeerVpcId"), peer_region
)
from moto.ec2.models import ec2_backends
peer_vpc = ec2_backends[peer_region].get_vpc(self._get_param("PeerVpcId"))
vpc = self.ec2_backend.get_vpc(self._get_param("VpcId"))
vpc_pcx = self.ec2_backend.create_vpc_peering_connection(vpc, peer_vpc, tags)
template = self.response_template(CREATE_VPC_PEERING_CONNECTION_RESPONSE)