Skip to content

Commit

Permalink
EC2 - Cross region VPC peering bug (#4764)
Browse files Browse the repository at this point in the history
  • Loading branch information
bblommers authored Jan 15, 2022
1 parent f45da41 commit 8f63ce0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
14 changes: 0 additions & 14 deletions moto/ec2/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3919,13 +3919,6 @@ def __init__(self):
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,
Expand Down Expand Up @@ -3975,13 +3968,6 @@ def get_vpc(self, vpc_id):
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:
Expand Down
6 changes: 3 additions & 3 deletions moto/ec2/responses/vpc_peering_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ def create_vpc_peering_connection(self):
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)
Expand Down

0 comments on commit 8f63ce0

Please sign in to comment.