cf_factory 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/cf_factory +9 -0
- data/examples/base_vpc.rb +9 -9
- data/examples/cloudfront_private.rb +23 -0
- data/examples/cloudinit_script_for_one_instance.rb +25 -25
- data/examples/cloudinit_script_with_autoscaling.rb +31 -31
- data/examples/dynamodb_table.rb +24 -0
- data/examples/elastic_beanstalk_example.rb +23 -0
- data/examples/elb_with_cloudfront.rb +34 -35
- data/examples/instance_with_eip.rb +13 -11
- data/examples/instance_with_yum.rb +13 -11
- data/examples/just_an_instance.rb +8 -6
- data/examples/nat_mutual_monitoring.rb +69 -0
- data/examples/play_with_region_and_zones.rb +11 -9
- data/examples/ra_web_hosting.rb +46 -44
- data/examples/s3_with_cloudfront.rb +11 -12
- data/examples/test_vpc.rb +27 -19
- data/lib/cf_factory/as/cf_as_group.rb +2 -0
- data/lib/cf_factory/as/cf_as_launch_config.rb +2 -0
- data/lib/cf_factory/as/cf_as_scaling_policy.rb +2 -0
- data/lib/cf_factory/base/cf_base.rb +5 -0
- data/lib/cf_factory/base/cf_ec2_tag.rb +2 -0
- data/lib/cf_factory/base/cf_generator.rb +2 -0
- data/lib/cf_factory/base/cf_helper.rb +2 -0
- data/lib/cf_factory/base/cf_inner.rb +27 -8
- data/lib/cf_factory/base/cf_main.rb +3 -1
- data/lib/cf_factory/base/cf_mapping.rb +3 -1
- data/lib/cf_factory/base/cf_named_inner.rb +1 -0
- data/lib/cf_factory/base/cf_output.rb +2 -0
- data/lib/cf_factory/base/cf_parameter.rb +2 -0
- data/lib/cf_factory/base/cf_script_reader.rb +3 -1
- data/lib/cf_factory/cloudformation/cf_cloud_formation_init.rb +2 -0
- data/lib/cf_factory/cloudformation/cf_cloudformation_command.rb +2 -0
- data/lib/cf_factory/cloudformation/cf_cloudformation_commands.rb +2 -0
- data/lib/cf_factory/cloudformation/cf_cloudformation_config.rb +2 -0
- data/lib/cf_factory/cloudformation/cf_cloudformation_file.rb +2 -0
- data/lib/cf_factory/cloudformation/cf_cloudformation_files.rb +2 -0
- data/lib/cf_factory/cloudformation/cf_cloudformation_inner.rb +2 -0
- data/lib/cf_factory/cloudformation/cf_cloudformation_package.rb +2 -0
- data/lib/cf_factory/cloudformation/cf_cloudformation_packages.rb +2 -0
- data/lib/cf_factory/cloudformation/cf_cloudformation_sources.rb +2 -0
- data/lib/cf_factory/cloudformation/cf_init_script.rb +7 -0
- data/lib/cf_factory/cloudfront/cf_cache_behavior.rb +2 -0
- data/lib/cf_factory/cloudfront/cf_cache_behaviors.rb +3 -1
- data/lib/cf_factory/cloudfront/cf_cloudfront_distribution.rb +2 -0
- data/lib/cf_factory/cloudfront/cf_custom_origin_config.rb +3 -1
- data/lib/cf_factory/cloudfront/cf_default_cache_behavior.rb +3 -1
- data/lib/cf_factory/cloudfront/cf_distribution_config.rb +4 -2
- data/lib/cf_factory/cloudfront/cf_forwarded_values.rb +3 -1
- data/lib/cf_factory/cloudfront/cf_logging.rb +3 -1
- data/lib/cf_factory/cloudfront/cf_origin.rb +3 -1
- data/lib/cf_factory/cloudfront/cf_s3_origin_config.rb +3 -1
- data/lib/cf_factory/cloudwatch/cf_cloud_watch_alarm.rb +2 -0
- data/lib/cf_factory/dynamo/cf_dynamo_table.rb +45 -0
- data/lib/cf_factory/eb/cd_eb_solution_stack.rb +28 -0
- data/lib/cf_factory/eb/cf_eb_application.rb +41 -0
- data/lib/cf_factory/eb/cf_eb_application_version.rb +24 -0
- data/lib/cf_factory/eb/cf_eb_configuration_template.rb +36 -0
- data/lib/cf_factory/eb/cf_eb_environment.rb +56 -0
- data/lib/cf_factory/eb/cf_eb_option_setting.rb +19 -0
- data/lib/cf_factory/ec2/cf_ebs_volume.rb +2 -0
- data/lib/cf_factory/ec2/cf_ec2_instance.rb +5 -1
- data/lib/cf_factory/ec2/cf_ec2_security_group.rb +2 -0
- data/lib/cf_factory/ec2/cf_ec2_security_group_egress.rb +3 -1
- data/lib/cf_factory/ec2/cf_ec2_security_group_ingress.rb +3 -1
- data/lib/cf_factory/ec2/cf_eip.rb +2 -0
- data/lib/cf_factory/ec2/cf_eip_association.rb +3 -1
- data/lib/cf_factory/elb/cf_app_cookie_stickiness_policy.rb +3 -1
- data/lib/cf_factory/elb/cf_elb.rb +3 -1
- data/lib/cf_factory/elb/cf_health_check.rb +3 -1
- data/lib/cf_factory/elb/cf_lb_cookie_stickiness_policy.rb +3 -1
- data/lib/cf_factory/elb/cf_listener.rb +3 -1
- data/lib/cf_factory/help/fixes.rb +1 -0
- data/lib/cf_factory/help/ip_mask.rb +2 -0
- data/lib/cf_factory/help/template_validation.rb +3 -1
- data/lib/cf_factory/iam/cf_iam_access_key.rb +3 -1
- data/lib/cf_factory/iam/cf_iam_group.rb +3 -1
- data/lib/cf_factory/iam/cf_iam_instance_profile.rb +3 -1
- data/lib/cf_factory/iam/cf_iam_policy.rb +2 -0
- data/lib/cf_factory/iam/cf_iam_role.rb +3 -1
- data/lib/cf_factory/iam/cf_iam_statement.rb +2 -0
- data/lib/cf_factory/iam/cf_iam_user.rb +3 -1
- data/lib/cf_factory/iam/cf_policy_document.rb +3 -1
- data/lib/cf_factory/modules/base_vpc.rb +2 -0
- data/lib/cf_factory/rds/cf_rds_instance.rb +3 -1
- data/lib/cf_factory/rds/cf_rds_security_group.rb +3 -1
- data/lib/cf_factory/rds/cf_rds_security_group_ingress.rb +3 -1
- data/lib/cf_factory/rds/cf_rds_subnet_group.rb +3 -1
- data/lib/cf_factory/route53/cf_elb_alias_target.rb +2 -0
- data/lib/cf_factory/route53/cf_record_set.rb +2 -0
- data/lib/cf_factory/route53/cf_route53_record_set.rb +2 -0
- data/lib/cf_factory/route53/cf_route53_record_set_group.rb +2 -0
- data/lib/cf_factory/s3/cf_s3_bucket.rb +2 -0
- data/lib/cf_factory/s3/cf_web_site_config.rb +3 -1
- data/lib/cf_factory/sqs/cf_sqs_queue.rb +3 -1
- data/lib/cf_factory/vpc/cf_attach_gateway.rb +3 -1
- data/lib/cf_factory/vpc/cf_internet_gateway.rb +2 -0
- data/lib/cf_factory/vpc/cf_network_acl.rb +3 -1
- data/lib/cf_factory/vpc/cf_network_acl_association.rb +3 -1
- data/lib/cf_factory/vpc/cf_network_acl_entry.rb +2 -0
- data/lib/cf_factory/vpc/cf_route.rb +3 -1
- data/lib/cf_factory/vpc/cf_route_table.rb +3 -1
- data/lib/cf_factory/vpc/cf_route_table_association.rb +3 -1
- data/lib/cf_factory/vpc/cf_subnet.rb +3 -1
- data/lib/cf_factory/vpc/cf_vpc.rb +3 -1
- data/lib/cf_factory.rb +2 -93
- metadata +39 -4
@@ -0,0 +1,69 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'cf_factory'
|
4
|
+
|
5
|
+
cf = CfFactory::CfMain.new("NAT Mutual Monitoring")
|
6
|
+
####### input parameters
|
7
|
+
param_keyname = CfFactory::CfParameter.new("KeyName", "Name of the key", "String", {"Default" => "majung"})
|
8
|
+
cf.add_parameter(param_keyname)
|
9
|
+
param_vpc_cidr = CfFactory::CfParameter.new("VpcCidr", "CIDR of the VPC", "String", {"Default" => "10.0.0.0/16"})
|
10
|
+
cf.add_parameter(param_vpc_cidr)
|
11
|
+
param_nat_type = CfFactory::CfParameter.new("NatInstanceType", "Type/size of the NAT instances", "String", {"Default" => "m1.small", "AllowedValues" => CfFactory::CfEc2Instance::SUPPORTED_TYPES})
|
12
|
+
cf.add_parameter(param_nat_type)
|
13
|
+
|
14
|
+
####### mappings
|
15
|
+
mapping = CfFactory::CfMapping.new("NatMapping","AMI", {"eu-west-1" => "ami-0b5b6c7f", "us-east-1" => "ami-f619c29f"})
|
16
|
+
cf.add_mapping(mapping)
|
17
|
+
|
18
|
+
####### resources
|
19
|
+
#vpc
|
20
|
+
base_vpc = CfFactory::BaseVpc.new("BaseVpc","192.168.0.0/16",2,2,["eu-west-1a","eu-west-1b"],256)
|
21
|
+
base_vpc.add_to_template(cf)
|
22
|
+
vpc = base_vpc.vpc
|
23
|
+
public_sn1, public_sn2, private_sn1, private_sn2 = base_vpc.subnets
|
24
|
+
|
25
|
+
#iam
|
26
|
+
commands = ["ec2:DescribeInstances","ec2:DescribeRouteTables", "ec2:ReplaceRoute","ec2:StartInstances","ec2:StopInstances"]
|
27
|
+
statement = CfFactory::CfIamStatement.new("Allow",commands,"*")
|
28
|
+
role_policy = CfFactory::CfIamPolicy.new("MyRolePolicy", CfFactory::CfPolicyDocument.new([statement]))
|
29
|
+
nat_role = CfFactory::CfIamRole.new("NatRole", "/", {:policies => [role_policy]} )
|
30
|
+
cf.add_resource(nat_role)
|
31
|
+
|
32
|
+
#nats
|
33
|
+
script = CfFactory::CfHelper.join([
|
34
|
+
"#!/bin/bash -v\\n",
|
35
|
+
"yum update -y aws*\\n"
|
36
|
+
]
|
37
|
+
)
|
38
|
+
nat1 = CfFactory::CfEc2Instance.new("Nat1",mapping.generate_ref("AWS::Region"),param_nat_type.generate_ref, {:keyname => param_keyname.generate_ref(), :subnet => private_sn1, :user_data => script})
|
39
|
+
cf.add_resource(nat1)
|
40
|
+
eip1 = CfFactory::CfEip.new("Eip1",nat1,true)
|
41
|
+
cf.add_resource(eip1)
|
42
|
+
nat2 = CfFactory::CfEc2Instance.new("Nat2",mapping.generate_ref("AWS::Region"),param_nat_type.generate_ref, {:keyname => param_keyname.generate_ref(), :subnet => private_sn2, :user_data => script})
|
43
|
+
cf.add_resource(nat2)
|
44
|
+
eip2 = CfFactory::CfEip.new("Eip2",nat2,true)
|
45
|
+
cf.add_resource(eip2)
|
46
|
+
nat_sg = CfFactory::CfEc2SecurityGroup.new("NatSecurityGroup","Rules for allowing access to HA Nodes",vpc)
|
47
|
+
cf.add_resource(nat_sg)
|
48
|
+
nat_sg.add_ingress_rule(CfFactory::CfEc2SecurityGroupIngress.new("tcp",22,22,"0.0.0.0/0",nil))
|
49
|
+
nat_sg.add_ingress_rule(CfFactory::CfEc2SecurityGroupIngress.new("-1",0,0,param_vpc_cidr.generate_ref(),nil))
|
50
|
+
nat_sg.add_egress_rule(CfFactory::CfEc2SecurityGroupEgress.new("-1",0,0,"0.0.0.0/0",nil))
|
51
|
+
|
52
|
+
####### output parameters
|
53
|
+
out_vpc = CfFactory::CfOutput.new("BaseVpc", "Id of the VPC", vpc.generate_ref())
|
54
|
+
cf.add_output(out_vpc)
|
55
|
+
out_nat1 = CfFactory::CfOutput.new("OutNat1","EIP of NAT1",eip1.generate_ref())
|
56
|
+
cf.add_output(out_nat1)
|
57
|
+
out_nat2 = CfFactory::CfOutput.new("OutNat2","EIP of NAT2",eip2.generate_ref())
|
58
|
+
cf.add_output(out_nat2)
|
59
|
+
|
60
|
+
cf_json = cf.generate
|
61
|
+
puts cf_json
|
62
|
+
|
63
|
+
config_options = YAML.load_file("aws_config.yml")
|
64
|
+
#config_options["cloud_formation_endpoint"] = "cloudformation.us-east-1.amazonaws.com"
|
65
|
+
|
66
|
+
validator = CfFactory::TemplateValidation.new(cf_json, config_options)
|
67
|
+
validator.validate()
|
68
|
+
|
69
|
+
#puts "the reference for the VPC : #{vpc.generate_ref}"
|
@@ -1,18 +1,20 @@
|
|
1
|
-
|
1
|
+
#!/usr/bin/ruby
|
2
2
|
|
3
|
-
|
3
|
+
require 'cf_factory'
|
4
|
+
|
5
|
+
cf = CfFactory::CfMain.new("Playground")
|
4
6
|
##########################
|
5
7
|
ami = "ami-6d555119"
|
6
8
|
|
7
|
-
az = CfHelper.az_in_region("a")
|
8
|
-
instance = CfEc2Instance.new("MyInstance", ami, "t1.micro", {:availability_zone => az })
|
9
|
+
az = CfFactory::CfHelper.az_in_region("a")
|
10
|
+
instance = CfFactory::CfEc2Instance.new("MyInstance", ami, "t1.micro", {:availability_zone => az })
|
9
11
|
cf.add_resource(instance)
|
10
12
|
|
11
|
-
region_output = CfOutput.new("Region", "Region the stack was started", CfHelper.ref_current_region())
|
13
|
+
region_output = CfFactory::CfOutput.new("Region", "Region the stack was started", CfFactory::CfHelper.ref_current_region())
|
12
14
|
cf.add_output(region_output)
|
13
|
-
target_zone_output = CfOutput.new("TargetZone", "AZ where instance to be started", az)
|
15
|
+
target_zone_output = CfFactory::CfOutput.new("TargetZone", "AZ where instance to be started", az)
|
14
16
|
cf.add_output(target_zone_output)
|
15
|
-
actual_zone_output = CfOutput.new("ActualInstanceZone", "AZ of started instance", instance.retrieve_attribute("AvailabilityZone"))
|
17
|
+
actual_zone_output = CfFactory::CfOutput.new("ActualInstanceZone", "AZ of started instance", instance.retrieve_attribute("AvailabilityZone"))
|
16
18
|
cf.add_output(actual_zone_output)
|
17
19
|
|
18
20
|
##########################
|
@@ -20,7 +22,7 @@ cf_json = cf.generate
|
|
20
22
|
puts cf_json
|
21
23
|
|
22
24
|
config_options = YAML.load_file("aws_config.yml")
|
23
|
-
validator = TemplateValidation.new(cf_json, config_options)
|
25
|
+
validator = CfFactory::TemplateValidation.new(cf_json, config_options)
|
24
26
|
validator.validate()
|
25
|
-
|
27
|
+
|
26
28
|
|
data/examples/ra_web_hosting.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'cf_factory'
|
2
4
|
|
3
5
|
# CloudFormation template for Atraveo. 2-Tiered web-application with load-balancing.
|
4
|
-
cf = CfMain.new("Reference Architecture Web-Hosting")
|
6
|
+
cf = CfFactory::CfMain.new("Reference Architecture Web-Hosting")
|
5
7
|
|
6
8
|
####### input parameters
|
7
9
|
hosted_zone_id = "ZSSFB90C439AA"
|
@@ -11,17 +13,17 @@ hosted_zone_name = "dezidr.com"
|
|
11
13
|
#ami_id = "ami-e96bdf80" #eu-west NAT instance
|
12
14
|
ami_id = "ami-e96bdf80" #us-east web-server returning something
|
13
15
|
|
14
|
-
param_hosted_zone = CfParameter.new("HostedZoneId", "Needs an existing hosted zone in Route53 to be configured", "String", {"Default" => hosted_zone_id})
|
16
|
+
param_hosted_zone = CfFactory::CfParameter.new("HostedZoneId", "Needs an existing hosted zone in Route53 to be configured", "String", {"Default" => hosted_zone_id})
|
15
17
|
cf.add_parameter(param_hosted_zone)
|
16
|
-
param_app_server_ami = CfParameter.new("AppServerAmi", "AMI of App-Server", "String", {"Default" => ami_id})
|
18
|
+
param_app_server_ami = CfFactory::CfParameter.new("AppServerAmi", "AMI of App-Server", "String", {"Default" => ami_id})
|
17
19
|
cf.add_parameter(param_app_server_ami)
|
18
|
-
param_app_server_key = CfParameter.new("AppServerKey", "Key used to start App-Server", "String")
|
20
|
+
param_app_server_key = CfFactory::CfParameter.new("AppServerKey", "Key used to start App-Server", "String")
|
19
21
|
cf.add_parameter(param_app_server_key)
|
20
|
-
param_app_port = CfParameter.new("AppPort", "Port of the Web/App-Servers", "Number", {"Default" => "8080"})
|
22
|
+
param_app_port = CfFactory::CfParameter.new("AppPort", "Port of the Web/App-Servers", "Number", {"Default" => "8080"})
|
21
23
|
cf.add_parameter(param_app_port)
|
22
|
-
param_db_user = CfParameter.new("MasterUserName", "Name of the master user name of the DB", "String", {"Default" => "masteruser"})
|
24
|
+
param_db_user = CfFactory::CfParameter.new("MasterUserName", "Name of the master user name of the DB", "String", {"Default" => "masteruser"})
|
23
25
|
cf.add_parameter(param_db_user)
|
24
|
-
param_db_pw = CfParameter.new("MasterPassword", "Password of the master user of the DB", "String")
|
26
|
+
param_db_pw = CfFactory::CfParameter.new("MasterPassword", "Password of the master user of the DB", "String")
|
25
27
|
cf.add_parameter(param_db_pw)
|
26
28
|
|
27
29
|
zone = "us-east"
|
@@ -31,12 +33,12 @@ zone = "us-east"
|
|
31
33
|
####### resources
|
32
34
|
|
33
35
|
#ebs test
|
34
|
-
ebs = CfEbsVolume.create_normal("MyEbs",CfHelper.az_in_region(az_id = "b"), 5)
|
36
|
+
ebs = CfFactory::CfEbsVolume.create_normal("MyEbs",CfFactory::CfHelper.az_in_region(az_id = "b"), 5)
|
35
37
|
cf.add_resource(ebs)
|
36
38
|
|
37
|
-
s3_bucket = CfS3Bucket.new("MyS3Bucket")
|
39
|
+
s3_bucket = CfFactory::CfS3Bucket.new("MyS3Bucket")
|
38
40
|
cf.add_resource(s3_bucket)
|
39
|
-
s3_log_bucket = CfS3Bucket.new("MyS3LogBucket")
|
41
|
+
s3_log_bucket = CfFactory::CfS3Bucket.new("MyS3LogBucket")
|
40
42
|
s3_log_bucket.set_deletion_policy("Delete")
|
41
43
|
cf.add_resource(s3_log_bucket)
|
42
44
|
|
@@ -50,23 +52,23 @@ cf.add_resource(s3_log_bucket)
|
|
50
52
|
#elb
|
51
53
|
#health_check_string = "HTTP:#{param_app_port.generate_ref()}/index.html"
|
52
54
|
health_check_string = "HTTP:80/index.html"
|
53
|
-
elb = CfElb.new("MyLoadBalancer", {
|
54
|
-
:health_check => CfHealthCheck.new("3","60", health_check_string,"10","2"),
|
55
|
-
:listeners => [CfListener.new(param_app_port.generate_ref(),"http","80","http")],
|
55
|
+
elb = CfFactory::CfElb.new("MyLoadBalancer", {
|
56
|
+
:health_check => CfFactory::CfHealthCheck.new("3","60", health_check_string,"10","2"),
|
57
|
+
:listeners => [CfFactory::CfListener.new(param_app_port.generate_ref(),"http","80","http")],
|
56
58
|
#:security_groups => [elb_sec_group], #only for VPC based ELBs
|
57
|
-
:availability_zones => CfHelper.availability_zones()
|
59
|
+
:availability_zones => CfFactory::CfHelper.availability_zones()
|
58
60
|
}
|
59
61
|
)
|
60
62
|
cf.add_resource(elb)
|
61
63
|
|
62
|
-
app_sec_group = CfEc2SecurityGroup.new("AppSecurityGroup", "Security Group for web and app")
|
63
|
-
app_sec_group.add_ingress_rule(CfEc2SecurityGroupIngress.new("tcp", 22, 22, "0.0.0.0/0"))
|
64
|
-
ir1 = CfEc2SecurityGroupIngress.new("tcp", param_app_port.generate_ref(), param_app_port.generate_ref(), "0.0.0.0/0")
|
64
|
+
app_sec_group = CfFactory::CfEc2SecurityGroup.new("AppSecurityGroup", "Security Group for web and app")
|
65
|
+
app_sec_group.add_ingress_rule(CfFactory::CfEc2SecurityGroupIngress.new("tcp", 22, 22, "0.0.0.0/0"))
|
66
|
+
ir1 = CfFactory::CfEc2SecurityGroupIngress.new("tcp", param_app_port.generate_ref(), param_app_port.generate_ref(), "0.0.0.0/0")
|
65
67
|
app_sec_group.add_ingress_rule(ir1)
|
66
68
|
cf.add_resource(app_sec_group)
|
67
69
|
|
68
|
-
rds_sec_group = CfRdsSecurityGroup.new("RdsSecurityGroup","Security Group for RDS")
|
69
|
-
ir = CfRdsSecurityGroupIngress.new(nil,app_sec_group)
|
70
|
+
rds_sec_group = CfFactory::CfRdsSecurityGroup.new("RdsSecurityGroup","Security Group for RDS")
|
71
|
+
ir = CfFactory::CfRdsSecurityGroupIngress.new(nil,app_sec_group)
|
70
72
|
ir.set_use_sg_id(false)
|
71
73
|
rds_sec_group.add_rule(ir)
|
72
74
|
cf.add_resource(rds_sec_group)
|
@@ -74,29 +76,29 @@ cf.add_resource(rds_sec_group)
|
|
74
76
|
#rds
|
75
77
|
rds_endpoint= "rdsendpoint"
|
76
78
|
options = {:multi_az => true, :security_groups => [rds_sec_group]}
|
77
|
-
rds_instance = CfRdsInstance.new("MyDatabase",5,"MySql","db.t1.micro",param_db_user.generate_ref(), param_db_pw.generate_ref, options)
|
79
|
+
rds_instance = CfFactory::CfRdsInstance.new("MyDatabase",5,"MySql","db.t1.micro",param_db_user.generate_ref(), param_db_pw.generate_ref, options)
|
78
80
|
cf.add_resource(rds_instance)
|
79
81
|
rds_endpoint = rds_instance.retrieve_attribute("Endpoint.Address")
|
80
82
|
|
81
83
|
#iam-role to be able to read meta-data
|
82
|
-
statement = CfIamStatement.new("Allow","cloudformation:DescribeStackResource","*")
|
83
|
-
role_policy = CfIamPolicy.new("MyRolePolicy", CfPolicyDocument.new([statement]))
|
84
|
-
iam_role = CfIamRole.new("ReadMetaData","/",{:policies => [role_policy]})
|
84
|
+
statement = CfFactory::CfIamStatement.new("Allow","cloudformation:DescribeStackResource","*")
|
85
|
+
role_policy = CfFactory::CfIamPolicy.new("MyRolePolicy", CfFactory::CfPolicyDocument.new([statement]))
|
86
|
+
iam_role = CfFactory::CfIamRole.new("ReadMetaData","/",{:policies => [role_policy]})
|
85
87
|
cf.add_resource(iam_role)
|
86
88
|
|
87
89
|
#auto-scaling group
|
88
|
-
launch_config = CfAsLaunchConfig.new("AppServerLaunchConfig", ami_id, "t1.micro", {:security_groups => [app_sec_group], :user_data => rds_endpoint})
|
90
|
+
launch_config = CfFactory::CfAsLaunchConfig.new("AppServerLaunchConfig", ami_id, "t1.micro", {:security_groups => [app_sec_group], :user_data => rds_endpoint})
|
89
91
|
cf.add_resource(launch_config)
|
90
|
-
availability_zones = CfHelper.az_array_in_region(["b","c"])
|
91
|
-
as_group = CfAsGroup.new("AppServerFleet",availability_zones, launch_config, [elb], 4 ,2 ,{:desired_capacity => 2})
|
92
|
+
availability_zones = CfFactory::CfHelper.az_array_in_region(["b","c"])
|
93
|
+
as_group = CfFactory::CfAsGroup.new("AppServerFleet",availability_zones, launch_config, [elb], 4 ,2 ,{:desired_capacity => 2})
|
92
94
|
cf.add_resource(as_group)
|
93
|
-
as_up_scaling_policy = CfAsScalingPolicy.new("MyUpscalePolicy",as_group,"ChangeInCapacity","1",{:cooldown => 300})
|
95
|
+
as_up_scaling_policy = CfFactory::CfAsScalingPolicy.new("MyUpscalePolicy",as_group,"ChangeInCapacity","1",{:cooldown => 300})
|
94
96
|
cf.add_resource(as_up_scaling_policy)
|
95
|
-
as_down_scaling_policy = CfAsScalingPolicy.new("MyDownscalePolicy",as_group,"ChangeInCapacity","-1",{:cooldown => 300})
|
97
|
+
as_down_scaling_policy = CfFactory::CfAsScalingPolicy.new("MyDownscalePolicy",as_group,"ChangeInCapacity","-1",{:cooldown => 300})
|
96
98
|
cf.add_resource(as_down_scaling_policy)
|
97
|
-
as_up_alarm = CfCloudWatchAlarm.new("MyUpAlarm",CfCloudWatchAlarm::GREATER_THAN_OR_EQUAL_TO_THRESHOLD, "3", "CPUUtilization","AWS/EC2",
|
99
|
+
as_up_alarm = CfFactory::CfCloudWatchAlarm.new("MyUpAlarm",CfFactory::CfCloudWatchAlarm::GREATER_THAN_OR_EQUAL_TO_THRESHOLD, "3", "CPUUtilization","AWS/EC2",
|
98
100
|
"60","Average","80", {:alarm_actions => [as_up_scaling_policy]})
|
99
|
-
as_down_alarm = CfCloudWatchAlarm.new("MyDownAlarm",CfCloudWatchAlarm::LESS_THAN_THRESHOLD, "3", "CPUUtilization","AWS/EC2",
|
101
|
+
as_down_alarm = CfFactory::CfCloudWatchAlarm.new("MyDownAlarm",CfFactory::CfCloudWatchAlarm::LESS_THAN_THRESHOLD, "3", "CPUUtilization","AWS/EC2",
|
100
102
|
"60","Average","30", {:alarm_actions => [as_down_scaling_policy]})
|
101
103
|
cf.add_resource(as_up_alarm)
|
102
104
|
cf.add_resource(as_down_alarm)
|
@@ -104,33 +106,33 @@ cf.add_resource(as_down_alarm)
|
|
104
106
|
#cloudfront
|
105
107
|
# distribution with multiple origins, one for S3, one for the ELB
|
106
108
|
#define origins
|
107
|
-
elb_origin = CfOrigin.create_elb_origin(elb)
|
108
|
-
s3_origin = CfOrigin.create_s3_origin(s3_bucket)
|
109
|
+
elb_origin = CfFactory::CfOrigin.create_elb_origin(elb)
|
110
|
+
s3_origin = CfFactory::CfOrigin.create_s3_origin(s3_bucket)
|
109
111
|
origins = [elb_origin, s3_origin]
|
110
112
|
#define cache behaviors for origins
|
111
|
-
default_cache_behavior = CfDefaultCacheBehavior.create_basic(elb_origin.id)
|
113
|
+
default_cache_behavior = CfFactory::CfDefaultCacheBehavior.create_basic(elb_origin.id)
|
112
114
|
cache_behaviors = [
|
113
|
-
CfCacheBehavior.create_basic(s3_origin.id, "/static/*", :min_ttl => 24*60*60),
|
114
|
-
CfCacheBehavior.create_basic(s3_origin.id, "*.jpg", :min_ttl => 24*60*60)
|
115
|
+
CfFactory::CfCacheBehavior.create_basic(s3_origin.id, "/static/*", :min_ttl => 24*60*60),
|
116
|
+
CfFactory::CfCacheBehavior.create_basic(s3_origin.id, "*.jpg", :min_ttl => 24*60*60)
|
115
117
|
]
|
116
118
|
#tie everything together
|
117
119
|
cname_endpoint = "cached-elb-#{(Random.new.rand*100000).to_i}.dezidr.com"
|
118
|
-
logging = CfLogging.new(s3_log_bucket,"log-") #activate logging
|
119
|
-
cf_distribution = CfCloudfrontDistribution.create_multi_origin_distribution("MyDistribution", origins,
|
120
|
+
logging = CfFactory::CfLogging.new(s3_log_bucket,"log-") #activate logging
|
121
|
+
cf_distribution = CfFactory::CfCloudfrontDistribution.create_multi_origin_distribution("MyDistribution", origins,
|
120
122
|
default_cache_behavior, cache_behaviors, {:logging => logging, :aliases => [cname_endpoint]})
|
121
123
|
cf.add_resource(cf_distribution)
|
122
124
|
|
123
125
|
#route53
|
124
126
|
cloudfront_dns = cf_distribution.retrieve_attribute("DomainName")
|
125
|
-
cname = CfRoute53RecordSet.new("CnameRecord", "#{cname_endpoint}", "CNAME", {:ttl => 1, :resource_records => [cloudfront_dns], :hosted_zone_id => hosted_zone_id})
|
127
|
+
cname = CfFactory::CfRoute53RecordSet.new("CnameRecord", "#{cname_endpoint}", "CNAME", {:ttl => 1, :resource_records => [cloudfront_dns], :hosted_zone_id => hosted_zone_id})
|
126
128
|
cf.add_resource(cname)
|
127
|
-
elb_alias = CfRoute53RecordSet.new("ElbAliasRecord","elb-#{(Random.new.rand*100000).to_i}.#{hosted_zone_name}","A", {:alias_target => CfElbAliasTarget.new(elb), :hosted_zone_id => hosted_zone_id})
|
129
|
+
elb_alias = CfFactory::CfRoute53RecordSet.new("ElbAliasRecord","elb-#{(Random.new.rand*100000).to_i}.#{hosted_zone_name}","A", {:alias_target => CfFactory::CfElbAliasTarget.new(elb), :hosted_zone_id => hosted_zone_id})
|
128
130
|
cf.add_resource(elb_alias)
|
129
131
|
|
130
132
|
####### output parameters
|
131
|
-
elb_output = CfOutput.new("ElbEndpoint","Endpoint of the ELB",elb.retrieve_attribute("DNSName"))
|
133
|
+
elb_output = CfFactory::CfOutput.new("ElbEndpoint","Endpoint of the ELB",elb.retrieve_attribute("DNSName"))
|
132
134
|
cf.add_output(elb_output)
|
133
|
-
cloudfront_domain = CfOutput.new("CloudfrontDomain", "Endpoint of the CloudFront distribution", cf_distribution.retrieve_attribute("DomainName"))
|
135
|
+
cloudfront_domain = CfFactory::CfOutput.new("CloudfrontDomain", "Endpoint of the CloudFront distribution", cf_distribution.retrieve_attribute("DomainName"))
|
134
136
|
cf.add_output(cloudfront_domain)
|
135
137
|
|
136
138
|
cf_json = cf.generate
|
@@ -139,8 +141,8 @@ puts cf_json
|
|
139
141
|
config_options = YAML.load_file("aws_config.yml")
|
140
142
|
config_options["cloud_formation_endpoint"] = "cloudformation.us-east-1.amazonaws.com"
|
141
143
|
puts config_options.inspect
|
142
|
-
validator = TemplateValidation.new(cf_json, config_options)
|
144
|
+
validator = CfFactory::TemplateValidation.new(cf_json, config_options)
|
143
145
|
validator.validate()
|
144
146
|
#validator.apply({"AppServerAmi" => ami_id, "AppServerKey" => "majung", "AppPort" => "80", "MasterUserName" => "iamauser", "MasterPassword" => "abcd1234"})
|
145
147
|
|
146
|
-
#puts "the reference for the VPC : #{vpc.generate_ref}"
|
148
|
+
#puts "the reference for the VPC : #{vpc.generate_ref}"
|
@@ -1,7 +1,9 @@
|
|
1
|
-
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'cf_factory'
|
2
4
|
|
3
5
|
# CloudFormation template for Atraveo. 2-Tiered web-application with load-balancing.
|
4
|
-
cf = CfMain.new("S3 Bucket with CloudFront distribution")
|
6
|
+
cf = CfFactory::CfMain.new("S3 Bucket with CloudFront distribution")
|
5
7
|
|
6
8
|
####### input parameters
|
7
9
|
|
@@ -9,28 +11,25 @@ cf = CfMain.new("S3 Bucket with CloudFront distribution")
|
|
9
11
|
|
10
12
|
####### resources
|
11
13
|
|
12
|
-
s3_bucket = CfS3Bucket.new("OriginBucket")
|
14
|
+
s3_bucket = CfFactory::CfS3Bucket.new("OriginBucket")
|
13
15
|
cf.add_resource(s3_bucket)
|
14
|
-
s3_log_bucket = CfS3Bucket.new("LogBucket")
|
16
|
+
s3_log_bucket = CfFactory::CfS3Bucket.new("LogBucket")
|
15
17
|
|
16
18
|
#cloudfront
|
17
|
-
logging = CfLogging.new(s3_bucket,"MyDistribution")
|
19
|
+
logging = CfFactory::CfLogging.new(s3_bucket,"MyDistribution")
|
18
20
|
options = {:logging => logging}
|
19
|
-
cloudfront_distribution = CfCloudfrontDistribution.create_s3_distribution("MyS3Distribution",s3_bucket)
|
21
|
+
cloudfront_distribution = CfFactory::CfCloudfrontDistribution.create_s3_distribution("MyS3Distribution",s3_bucket)
|
20
22
|
cf.add_resource(cloudfront_distribution)
|
21
23
|
|
22
24
|
####### output parameters
|
23
|
-
s3_domain = CfOutput.new("S3Domain","Domain name of S3 bucket",s3_bucket.retrieve_attribute("DomainName"))
|
25
|
+
s3_domain = CfFactory::CfOutput.new("S3Domain","Domain name of S3 bucket",s3_bucket.retrieve_attribute("DomainName"))
|
24
26
|
cf.add_output(s3_domain)
|
25
|
-
cloudfront_domain = CfOutput.new("CloudfrontDomain", "Endpoint of the CloudFront distribution", cloudfront_distribution.retrieve_attribute("DomainName"))
|
27
|
+
cloudfront_domain = CfFactory::CfOutput.new("CloudfrontDomain", "Endpoint of the CloudFront distribution", cloudfront_distribution.retrieve_attribute("DomainName"))
|
26
28
|
cf.add_output(cloudfront_domain)
|
27
29
|
|
28
30
|
cf_json = cf.generate
|
29
31
|
puts cf_json
|
30
32
|
|
31
33
|
config_options = YAML.load_file("aws_config.yml")
|
32
|
-
validator = TemplateValidation.new(cf_json, config_options)
|
34
|
+
validator = CfFactory::TemplateValidation.new(cf_json, config_options)
|
33
35
|
validator.validate()
|
34
|
-
validator.apply()
|
35
|
-
|
36
|
-
#puts "the reference for the VPC : #{vpc.generate_ref}"
|
data/examples/test_vpc.rb
CHANGED
@@ -1,40 +1,42 @@
|
|
1
|
-
|
1
|
+
#!/usr/bin/ruby
|
2
2
|
|
3
|
-
|
3
|
+
require 'cf_factory'
|
4
|
+
|
5
|
+
cf = CfFactory::CfMain.new("Bla bla bla")
|
4
6
|
####### input parameters
|
5
|
-
parameter = CfParameter.new("KeyName", "Name of the key", "String", {"Default" => "majung"})
|
7
|
+
parameter = CfFactory::CfParameter.new("KeyName", "Name of the key", "String", {"Default" => "majung"})
|
6
8
|
cf.add_parameter(parameter)
|
7
|
-
parameter2 = CfParameter.new("SecurityGroup", "Name of the security group", "String", {"Default" => "Blubber"})
|
9
|
+
parameter2 = CfFactory::CfParameter.new("SecurityGroup", "Name of the security group", "String", {"Default" => "Blubber"})
|
8
10
|
cf.add_parameter(parameter2)
|
9
11
|
|
10
12
|
####### mappings
|
11
|
-
mapping = CfMapping.new("Default","AMI",{"us-east-1" => "ami-c6699baf", "us-west-2" => "ami-52ff7262"})
|
13
|
+
mapping = CfFactory::CfMapping.new("Default","AMI",{"us-east-1" => "ami-c6699baf", "us-west-2" => "ami-52ff7262"})
|
12
14
|
cf.add_mapping(mapping)
|
13
15
|
|
14
16
|
####### resources
|
15
17
|
#vpc
|
16
|
-
vpc = CfVpc.new("10.10.0.0/16")
|
18
|
+
vpc = CfFactory::CfVpc.new("10.10.0.0/16")
|
17
19
|
cf.add_vpc(vpc)
|
18
|
-
igw = CfInternetGateway.new("MyInternetGateway", vpc)
|
20
|
+
igw = CfFactory::CfInternetGateway.new("MyInternetGateway", vpc)
|
19
21
|
vpc.add_internet_gateway(igw)
|
20
|
-
route_table = CfRouteTable.new("MyRouteTable")
|
22
|
+
route_table = CfFactory::CfRouteTable.new("MyRouteTable")
|
21
23
|
vpc.add_route_table(route_table)
|
22
|
-
route1 = CfRoute.new("MyRoute1", "88.44.22.11/32", igw)
|
23
|
-
route2 = CfRoute.new("MyRoute2", "188.144.122.111/32", igw)
|
24
|
+
route1 = CfFactory::CfRoute.new("MyRoute1", "88.44.22.11/32", igw)
|
25
|
+
route2 = CfFactory::CfRoute.new("MyRoute2", "188.144.122.111/32", igw)
|
24
26
|
route_table.add_route(route1)
|
25
27
|
route_table.add_route(route2)
|
26
28
|
|
27
|
-
network_acl = CfNetworkAcl.new("MyAcl1")
|
29
|
+
network_acl = CfFactory::CfNetworkAcl.new("MyAcl1")
|
28
30
|
vpc.add_network_acl(network_acl)
|
29
|
-
network_acl_entry = CfNetworkAclEntry.new("Acl1", "110", "6", "ALLOW", false, "0.0.0.0/0", 80, 80)
|
31
|
+
network_acl_entry = CfFactory::CfNetworkAclEntry.new("Acl1", "110", "6", "ALLOW", false, "0.0.0.0/0", 80, 80)
|
30
32
|
network_acl.add_network_acl_entry(network_acl_entry)
|
31
33
|
|
32
|
-
subnet1 = CfSubnet.new("WebTier1", "10.10.0.0/24", "eu-west-1a", route_table, network_acl)
|
34
|
+
subnet1 = CfFactory::CfSubnet.new("WebTier1", "10.10.0.0/24", "eu-west-1a", route_table, network_acl)
|
33
35
|
vpc.add_subnet(subnet1)
|
34
|
-
subnet2 = CfSubnet.new("AppTier1", "10.10.1.0/24", "eu-west-1a", route_table, network_acl)
|
35
|
-
vpc.add_subnet(subnet2)
|
36
|
-
subnet3 = CfSubnet.new("DbTier1", "10.10.2.0/24", "eu-west-1a", route_table, network_acl)
|
36
|
+
subnet2 = CfFactory::CfSubnet.new("AppTier1", "10.10.1.0/24", "eu-west-1a", route_table, network_acl)
|
37
37
|
vpc.add_subnet(subnet2)
|
38
|
+
subnet3 = CfFactory::CfSubnet.new("DbTier1", "10.10.2.0/24", "eu-west-1a", route_table, network_acl)
|
39
|
+
vpc.add_subnet(subnet3)
|
38
40
|
|
39
41
|
#elb
|
40
42
|
#elb = CfElb.new("MyElb", {
|
@@ -44,10 +46,16 @@ vpc.add_subnet(subnet2)
|
|
44
46
|
#puts elb.get_cf_properties()
|
45
47
|
|
46
48
|
####### output parameters
|
47
|
-
output = CfOutput.new("
|
49
|
+
output = CfFactory::CfOutput.new("VpcId", "Id of the VPC", vpc.generate_ref())
|
48
50
|
cf.add_output(output)
|
49
51
|
|
50
52
|
|
51
|
-
|
53
|
+
cf_json = cf.generate
|
54
|
+
puts cf_json
|
55
|
+
|
56
|
+
config_options = YAML.load_file("aws_config.yml")
|
57
|
+
validator = CfFactory::TemplateValidation.new(cf_json, config_options)
|
58
|
+
validator.validate()
|
59
|
+
|
52
60
|
|
53
|
-
#puts "the reference for the VPC : #{vpc.generate_ref}"
|
61
|
+
#puts "the reference for the VPC : #{vpc.generate_ref}"
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'cf_factory/base/cf_helper'
|
2
2
|
|
3
|
+
module CfFactory
|
3
4
|
module CfBase
|
4
5
|
def get_name
|
5
6
|
@name
|
@@ -47,6 +48,8 @@ module CfBase
|
|
47
48
|
case value.class.to_s
|
48
49
|
when "Hash"
|
49
50
|
output += " \"#{key}\" : \n{#{hash_to_string(value,indent+5)}},\n"
|
51
|
+
when "EmbeddedProperty"
|
52
|
+
output += " \"#{key}\" : \n{#{hash_to_string(value.generate,indent+5)},\n"
|
50
53
|
else
|
51
54
|
output += " \"#{key}\" : #{set_quotes(value)},\n"
|
52
55
|
end
|
@@ -95,3 +98,5 @@ module CfBase
|
|
95
98
|
end
|
96
99
|
|
97
100
|
end
|
101
|
+
|
102
|
+
end
|
@@ -17,9 +17,13 @@ module CfInner
|
|
17
17
|
@result += "#{indent} \"#{@name}\" : {\n"
|
18
18
|
attributes.keys.each() {|key|
|
19
19
|
value = attributes[key]
|
20
|
-
|
20
|
+
if (not (value.class.to_s == "String")) and value.method_defined? :get_cf_attributes
|
21
|
+
@result += "#{indent} \"#{key}\" : #{value.get_cf_attributes},\n}"
|
22
|
+
else
|
23
|
+
@result += "#{indent} \"#{key}\" : #{set_quotes(value)},\n"
|
24
|
+
end
|
21
25
|
}
|
22
|
-
|
26
|
+
|
23
27
|
@result = @result.chomp.chomp(",")
|
24
28
|
@result += "\n#{indent} }"
|
25
29
|
@result += "\n#{indent} }"
|
@@ -30,14 +34,28 @@ module CfInner
|
|
30
34
|
@result = "#{indent}"
|
31
35
|
@result += "#{indent}{\n"
|
32
36
|
attributes = self.get_cf_attributes
|
33
|
-
attributes
|
34
|
-
|
35
|
-
@result += "#{indent} \"#{key}\" : #{set_quotes(value)},\n"
|
36
|
-
}
|
37
|
-
#
|
38
|
-
@result = @result.chomp.chomp(",")
|
37
|
+
@result += hash_to_string(attributes)
|
38
|
+
|
39
39
|
@result += "\n#{indent} }"
|
40
40
|
end
|
41
|
+
|
42
|
+
def hash_to_string(hash, indent=0)
|
43
|
+
output = ""
|
44
|
+
hash.keys.each() do |key|
|
45
|
+
value = hash[key]
|
46
|
+
output += " " * indent
|
47
|
+
case value.class.to_s
|
48
|
+
when "Hash"
|
49
|
+
output += " \"#{key}\" : \n{#{hash_to_string(value,indent+5)}},\n"
|
50
|
+
else
|
51
|
+
output += " \"#{key}\" : #{set_quotes(value)},\n"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
output
|
55
|
+
output = output.chomp().chomp(",")
|
56
|
+
|
57
|
+
end
|
58
|
+
|
41
59
|
|
42
60
|
# Sets leading and trailing quotes
|
43
61
|
def set_quotes(value)
|
@@ -53,3 +71,4 @@ module CfInner
|
|
53
71
|
end
|
54
72
|
|
55
73
|
end
|
74
|
+
|
@@ -1,3 +1,4 @@
|
|
1
|
+
module CfFactory
|
1
2
|
class CfMapping
|
2
3
|
def initialize(name, target, from_to_hash)
|
3
4
|
@name = name
|
@@ -23,4 +24,5 @@ class CfMapping
|
|
23
24
|
def map_from_region()
|
24
25
|
"{\"Fn::FindInMap\" : [ \"#{@name}\", \"#{CfHelper.ref_current_region()}\", \"#{@target}\" ]}"
|
25
26
|
end
|
26
|
-
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# Reads a file, integrates the specified arguments, and generates indented output taken specified parameters into account
|
2
|
+
module CfFactory
|
2
3
|
class CfScriptReader
|
3
4
|
def initialize(file_to_read, indentation = 0)
|
4
5
|
@file = file_to_read
|
@@ -29,4 +30,5 @@ class CfScriptReader
|
|
29
30
|
private
|
30
31
|
|
31
32
|
|
32
|
-
end
|
33
|
+
end
|
34
|
+
end
|