Created
August 21, 2018 18:10
-
-
Save astrobounce/3f4d7178201df0e210f4671b9d32f478 to your computer and use it in GitHub Desktop.
Main Template generation code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Sample Template Generation Code | |
from troposphere import GetAtt, Output, Template | |
from parameters import Parameters | |
from ec2_master import EC2_MASTER | |
from loadbalancer import LoadBalancer | |
from mappings import Mappings | |
import os | |
def main(): | |
template = Template() | |
parameters = Parameters() | |
template.add_description("This template creates Elasticsearch Cluster") | |
for key, value in Mappings().mappings.items(): | |
template.add_mapping(key, value) | |
for param in parameters.values(): | |
template.add_parameter(param) | |
template.add_metadata({ | |
"Author": "Arvind Sharma", | |
"LastUpdated": "2018-08-17", | |
"Version": "2", | |
}) | |
template.add_metadata( | |
{ | |
"AWS::CloudFormation::Interface": { | |
"ParameterGroups": [ | |
{ | |
"Label": {"default": "Global parameters"}, | |
"Parameters": ["VPC", "Subnets", "s3Bucket"] | |
}, | |
{ | |
"Label": {"default": "EC2"}, | |
"Parameters": ["ec2KeyPair", "instanceProfile", "amiName", "instanceSG"] | |
}, | |
{ | |
"Label": {"default": "Configure master nodes"}, | |
"Parameters": ["masterInstanceType", "numMasterNodes", "masterRootVolume", "masterDataVolume"] | |
}, | |
], | |
"ParameterLabels": { | |
"ec2KeyPair": {"default": "EC2 KeyPair"}, | |
"s3Bucket": {"default": "S3 Bucket"}, | |
"instanceProfile": {"default": "Instance Role"}, | |
"amiName": {"default": "Image AMI"}, | |
"numMasterNodes": {"default": "Number of Dedicated Master Nodes"}, | |
} | |
} | |
} | |
) | |
ec2 = EC2_MASTER(parameters=parameters) | |
for res in ec2.values(): | |
template.add_resource(res) | |
elb = LoadBalancer(parameters=parameters) | |
for res in elb.values(): | |
template.add_resource(res) | |
template.add_output(Output("Loadbalancer", Value=GetAtt(elb.load_balancer, "DNSName"))) | |
os.remove('templates/elasticsearch-cluster.template') | |
fhandle = open('templates/elasticsearch-cluster.template', 'w') | |
fhandle.write(template.to_yaml()) | |
fhandle.close() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment