Skip to content

Commit

Permalink
Attach internet gateway to VPC when it is created through CloudFormation
Browse files Browse the repository at this point in the history
  • Loading branch information
hltbra committed Feb 11, 2015
1 parent 170d09b commit 1546635
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
4 changes: 3 additions & 1 deletion moto/ec2/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2031,10 +2031,12 @@ def create_from_cloudformation_json(cls, resource_name, cloudformation_json, reg
properties = cloudformation_json['Properties']

ec2_backend = ec2_backends[region_name]
return ec2_backend.create_vpc_gateway_attachment(
attachment = ec2_backend.create_vpc_gateway_attachment(
gateway_id=properties['InternetGatewayId'],
vpc_id=properties['VpcId'],
)
ec2_backend.attach_internet_gateway(properties['InternetGatewayId'], properties['VpcId'])
return attachment

@property
def physical_resource_id(self):
Expand Down
48 changes: 48 additions & 0 deletions tests/test_cloudformation/test_cloudformation_stack_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -936,3 +936,51 @@ def test_sns_topic():
topic_name_output.value.should.equal("my_topics")
topic_arn_output = [x for x in stack.outputs if x.key == 'topic_arn'][0]
topic_arn_output.value.should.equal(topic_arn)



@mock_cloudformation
def test_vpc_gateway_attachment_creation_should_attach_itself_to_vpc():
template = {
"AWSTemplateFormatVersion": "2010-09-09",
"Resources": {
"internetgateway": {
"Type": "AWS::EC2::InternetGateway"
},
"testvpc": {
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": "10.0.0.0/16",
"EnableDnsHostnames": "true",
"EnableDnsSupport": "true",
"InstanceTenancy": "default"
},
},
"vpcgatewayattachment": {
"Type": "AWS::EC2::VPCGatewayAttachment",
"Properties": {
"InternetGatewayId": {
"Ref": "internetgateway"
},
"VpcId": {
"Ref": "testvpc"
}
},
},
}
}

template_json = json.dumps(template)
cf_conn = boto.cloudformation.connect_to_region("us-west-1")
cf_conn.create_stack(
"test_stack",
template_body=template_json,
)

vpc_conn = boto.vpc.connect_to_region("us-west-1")
vpc = vpc_conn.get_all_vpcs()[0]
igws = vpc_conn.get_all_internet_gateways(
filters={'attachment.vpc-id': vpc.id}
)

igws.should.have.length_of(1)

0 comments on commit 1546635

Please sign in to comment.