diff --git a/moto/ec2/.models.py.swp b/moto/ec2/.models.py.swp new file mode 100644 index 000000000..9c556ae1a Binary files /dev/null and b/moto/ec2/.models.py.swp differ diff --git a/moto/ec2/models.py b/moto/ec2/models.py index a80dd3cfc..0b4db0e28 100644 --- a/moto/ec2/models.py +++ b/moto/ec2/models.py @@ -901,6 +901,7 @@ class SubnetBackend(object): def create_subnet(self, vpc_id, cidr_block): subnet_id = random_subnet_id() subnet = Subnet(subnet_id, vpc_id, cidr_block) + vpc = self.get_vpc(vpc_id) # Validate VPC exists self.subnets[subnet_id] = subnet return subnet diff --git a/tests/test_ec2/.test_subnets.py.swp b/tests/test_ec2/.test_subnets.py.swp new file mode 100644 index 000000000..1d61bbc17 Binary files /dev/null and b/tests/test_ec2/.test_subnets.py.swp differ diff --git a/tests/test_ec2/test_subnets.py b/tests/test_ec2/test_subnets.py index 887e1eafa..37fd4007e 100644 --- a/tests/test_ec2/test_subnets.py +++ b/tests/test_ec2/test_subnets.py @@ -30,6 +30,17 @@ def test_subnets(): cm.exception.request_id.should_not.be.none +@mock_ec2 +def test_subnet_create_vpc_validation(): + conn = boto.connect_vpc('the_key', 'the_secret') + + with assert_raises(EC2ResponseError) as cm: + conn.create_subnet("vpc-abcd1234", "10.0.0.0/18") + cm.exception.code.should.equal('InvalidVpcID.NotFound') + cm.exception.status.should.equal(400) + cm.exception.request_id.should_not.be.none + + @mock_ec2 def test_subnet_tagging(): conn = boto.connect_vpc('the_key', 'the_secret')