Skip to content

Commit 4e35d8f

Browse files
rgarciacarmstrong
authored andcommitted
feat(contrib/ec2): launch into vpc
Modifies the cloudformation configuration to create resources within the confines of a VPC. fixes #1005
1 parent 32fc59f commit 4e35d8f

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

contrib/ec2/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ by adding a new entry to [cloudformation.json](cloudformation.json) like so:
6060
The only entry in cloudformation.json required to launch your cluster is `KeyPair`,
6161
which is already filled out. The defaults will be applied for the other settings.
6262

63+
## Choose whether to launch in VPC
64+
65+
To launch you cluster into a VPC, export two additional environment variables:
66+
67+
```
68+
export VPC_ID=vpc-a26218bf
69+
export VPC_SUBNETS=subnet-04d7f942,subnet-2b03ab7f
70+
```
71+
6372
## Run the provision script
6473
Run the [cloudformation provision script][pro-script] to spawn a new CoreOS cluster:
6574
```console

contrib/ec2/gen-json.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,21 @@
1010
template['Resources']['CoreOSServerLaunchConfig']['Properties']['UserData']['Fn::Base64']['Fn::Join'] = [ '', lines ]
1111
template['Parameters']['ClusterSize']['Default'] = str(os.getenv('DEIS_NUM_INSTANCES', 3))
1212

13+
if os.getenv("VPC_ID", None) and os.getenv("VPC_SUBNETS", None):
14+
for resource in template['Resources'].keys():
15+
resource_type = template['Resources'][resource]['Type']
16+
if resource_type == 'AWS::EC2::SecurityGroup':
17+
template['Resources'][resource]['Properties']['VpcId'] = os.getenv("VPC_ID")
18+
elif resource_type == 'AWS::EC2::SecurityGroupIngress':
19+
template['Resources'][resource]['Properties']['GroupId'] = template['Resources'][resource]['Properties']['GroupName']
20+
del template['Resources'][resource]['Properties']['GroupName']
21+
template['Resources'][resource]['Properties']['SourceSecurityGroupId'] = {
22+
'Ref': template['Resources'][resource]['Properties']['SourceSecurityGroupId']['Fn::GetAtt'][0]
23+
}
24+
elif resource_type == 'AWS::AutoScaling::LaunchConfiguration':
25+
template['Resources'][resource]['Properties']['AssociatePublicIpAddress'] = False
26+
elif resource_type == 'AWS::AutoScaling::AutoScalingGroup':
27+
template['Resources'][resource]['Properties']['VPCZoneIdentifier'] = os.getenv('VPC_SUBNETS').split(',')
28+
29+
1330
print json.dumps(template)

0 commit comments

Comments
 (0)