Skip to content

Commit d2583b2

Browse files
committed
Merge pull request #1232 from deis/aws_vpc
feat(contrib/ec2): launch into vpc
2 parents 461bbd2 + 9209f00 commit d2583b2

3 files changed

Lines changed: 51 additions & 0 deletions

File tree

contrib/ec2/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,25 @@ 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 into a VPC
64+
65+
The provision script supports launching into Amazon VPC. You'll need to have already created and
66+
configured your VPC with at least one subnet and an internet gateway for the nodes.
67+
68+
To launch your cluster into a VPC, export three additional environment variables: ```VPC_ID```,
69+
```VPC_SUBNETS```, ```VPC_ZONES```. ```VPC_ZONES``` must list the availability zones of the
70+
subnets in order.
71+
72+
For example, if your VPC has ID ```vpc-a26218bf``` and consists of the subnets ```subnet-04d7f942```
73+
(which is in ```us-east-1b```) and ```subnet-2b03ab7f``` (which is in ```us-east-1c```) you would
74+
export:
75+
76+
```
77+
export VPC_ID=vpc-a26218bf
78+
export VPC_SUBNETS=subnet-04d7f942,subnet-2b03ab7f
79+
export VPC_ZONES=us-east-1b,us-east-1c
80+
```
81+
6382
## Run the provision script
6483
Run the [cloudformation provision script][pro-script] to spawn a new CoreOS cluster:
6584
```console

contrib/ec2/gen-json.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,28 @@
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+
VPC_ID = os.getenv('VPC_ID', None)
14+
VPC_SUBNETS = os.getenv('VPC_SUBNETS', None)
15+
VPC_ZONES = os.getenv('VPC_ZONES', None)
16+
17+
if VPC_ID and VPC_SUBNETS and VPC_ZONES:
18+
for resource in template['Resources'].keys():
19+
resource_type = template['Resources'][resource]['Type']
20+
if resource_type == 'AWS::EC2::SecurityGroup':
21+
template['Resources'][resource]['Properties']['VpcId'] = VPC_ID
22+
elif resource_type == 'AWS::EC2::SecurityGroupIngress':
23+
template['Resources'][resource]['Properties']['GroupId'] = template['Resources'][resource]['Properties']['GroupName']
24+
del template['Resources'][resource]['Properties']['GroupName']
25+
template['Resources'][resource]['Properties']['SourceSecurityGroupId'] = {
26+
'Ref': template['Resources'][resource]['Properties']['SourceSecurityGroupId']['Fn::GetAtt'][0]
27+
}
28+
elif resource_type == 'AWS::AutoScaling::LaunchConfiguration':
29+
template['Resources'][resource]['Properties']['AssociatePublicIpAddress'] = False
30+
elif resource_type == 'AWS::ElasticLoadBalancing::LoadBalancer':
31+
del template['Resources'][resource]['Properties']['AvailabilityZones']
32+
template['Resources'][resource]['Properties']['Subnets'] = VPC_SUBNETS.split(',')
33+
elif resource_type == 'AWS::AutoScaling::AutoScalingGroup':
34+
template['Resources'][resource]['Properties']['VPCZoneIdentifier'] = VPC_SUBNETS.split(',')
35+
template['Resources'][resource]['Properties']['AvailabilityZones'] = VPC_ZONES.split(',')
36+
1337
print json.dumps(template)

contrib/ec2/provision-ec2-cluster.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ if [ -z "$DEIS_NUM_INSTANCES" ]; then
2020
DEIS_NUM_INSTANCES=3
2121
fi
2222

23+
# make sure we have all VPC info
24+
if [ -n "$VPC_ID" ]; then
25+
if [ -z "$VPC_SUBNETS" ] || [ -z "$VPC_ZONES" ]; then
26+
echo_red 'To provision Deis in a VPC, you must also specify VPC_SUBNETS and VPC_ZONES.'
27+
exit 1
28+
fi
29+
fi
30+
2331
# check that the CoreOS user-data file is valid
2432
$CONTRIB_DIR/util/check-user-data.sh
2533

0 commit comments

Comments
 (0)