-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgen-json.py
More file actions
executable file
·30 lines (24 loc) · 1.45 KB
/
gen-json.py
File metadata and controls
executable file
·30 lines (24 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python
import json
import os
template = json.load(open("deis.template",'r'))
with open('../coreos/user-data','r') as f:
lines = f.readlines()
template['Resources']['CoreOSServerLaunchConfig']['Properties']['UserData']['Fn::Base64']['Fn::Join'] = [ '', lines ]
template['Parameters']['ClusterSize']['Default'] = str(os.getenv('DEIS_NUM_INSTANCES', 3))
if os.getenv("VPC_ID", None) and os.getenv("VPC_SUBNETS", None):
for resource in template['Resources'].keys():
resource_type = template['Resources'][resource]['Type']
if resource_type == 'AWS::EC2::SecurityGroup':
template['Resources'][resource]['Properties']['VpcId'] = os.getenv("VPC_ID")
elif resource_type == 'AWS::EC2::SecurityGroupIngress':
template['Resources'][resource]['Properties']['GroupId'] = template['Resources'][resource]['Properties']['GroupName']
del template['Resources'][resource]['Properties']['GroupName']
template['Resources'][resource]['Properties']['SourceSecurityGroupId'] = {
'Ref': template['Resources'][resource]['Properties']['SourceSecurityGroupId']['Fn::GetAtt'][0]
}
elif resource_type == 'AWS::AutoScaling::LaunchConfiguration':
template['Resources'][resource]['Properties']['AssociatePublicIpAddress'] = False
elif resource_type == 'AWS::AutoScaling::AutoScalingGroup':
template['Resources'][resource]['Properties']['VPCZoneIdentifier'] = os.getenv('VPC_SUBNETS').split(',')
print json.dumps(template)