cf_factory 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/cf_factory +9 -9
- data/examples/base_vpc.rb +40 -40
- data/examples/cloudfront_private.rb +23 -23
- data/examples/cloudinit_script_for_one_instance.rb +77 -77
- data/examples/cloudinit_script_with_autoscaling.rb +85 -85
- data/examples/dynamodb_table.rb +24 -24
- data/examples/elastic_beanstalk_example.rb +23 -23
- data/examples/elb_with_cloudfront.rb +100 -100
- data/examples/instance_with_eip.rb +40 -40
- data/examples/instance_with_yum.rb +40 -40
- data/examples/just_an_instance.rb +31 -31
- data/examples/nat_mutual_monitoring.rb +69 -69
- data/examples/play_with_region_and_zones.rb +28 -28
- data/examples/ra_web_hosting.rb +148 -148
- data/examples/s3_with_cloudfront.rb +35 -35
- data/examples/test_vpc.rb +61 -61
- data/lib/cf_factory/as/cf_as_group.rb +80 -77
- data/lib/cf_factory/as/cf_as_launch_config.rb +55 -55
- data/lib/cf_factory/as/cf_as_scaling_policy.rb +35 -35
- data/lib/cf_factory/as/cf_as_update_policy.rb +23 -0
- data/lib/cf_factory/base/cf_base.rb +112 -102
- data/lib/cf_factory/base/cf_ec2_tag.rb +34 -34
- data/lib/cf_factory/base/cf_generator.rb +20 -20
- data/lib/cf_factory/base/cf_helper.rb +93 -93
- data/lib/cf_factory/base/cf_inner.rb +74 -74
- data/lib/cf_factory/base/cf_main.rb +103 -103
- data/lib/cf_factory/base/cf_mapping.rb +28 -28
- data/lib/cf_factory/base/cf_named_inner.rb +70 -1
- data/lib/cf_factory/base/cf_output.rb +26 -26
- data/lib/cf_factory/base/cf_parameter.rb +27 -27
- data/lib/cf_factory/base/cf_script_reader.rb +34 -34
- data/lib/cf_factory/cloudformation/cf_cloud_formation_init.rb +27 -27
- data/lib/cf_factory/cloudformation/cf_cloudformation_command.rb +39 -39
- data/lib/cf_factory/cloudformation/cf_cloudformation_commands.rb +27 -27
- data/lib/cf_factory/cloudformation/cf_cloudformation_config.rb +35 -35
- data/lib/cf_factory/cloudformation/cf_cloudformation_file.rb +40 -40
- data/lib/cf_factory/cloudformation/cf_cloudformation_files.rb +27 -27
- data/lib/cf_factory/cloudformation/cf_cloudformation_inner.rb +30 -30
- data/lib/cf_factory/cloudformation/cf_cloudformation_package.rb +36 -36
- data/lib/cf_factory/cloudformation/cf_cloudformation_packages.rb +44 -44
- data/lib/cf_factory/cloudformation/cf_cloudformation_sources.rb +32 -32
- data/lib/cf_factory/cloudformation/cf_init_script.rb +80 -80
- data/lib/cf_factory/cloudfront/cf_cache_behavior.rb +39 -39
- data/lib/cf_factory/cloudfront/cf_cache_behaviors.rb +30 -30
- data/lib/cf_factory/cloudfront/cf_cloudfront_distribution.rb +66 -66
- data/lib/cf_factory/cloudfront/cf_custom_origin_config.rb +39 -39
- data/lib/cf_factory/cloudfront/cf_default_cache_behavior.rb +34 -34
- data/lib/cf_factory/cloudfront/cf_distribution_config.rb +33 -33
- data/lib/cf_factory/cloudfront/cf_forwarded_values.rb +27 -27
- data/lib/cf_factory/cloudfront/cf_logging.rb +26 -26
- data/lib/cf_factory/cloudfront/cf_origin.rb +42 -42
- data/lib/cf_factory/cloudfront/cf_s3_origin_config.rb +27 -27
- data/lib/cf_factory/cloudwatch/cf_cloud_watch_alarm.rb +60 -60
- data/lib/cf_factory/dynamo/cf_dynamo_table.rb +45 -45
- data/lib/cf_factory/eb/cd_eb_solution_stack.rb +27 -28
- data/lib/cf_factory/eb/cf_eb_application.rb +41 -41
- data/lib/cf_factory/eb/cf_eb_application_version.rb +24 -24
- data/lib/cf_factory/eb/cf_eb_configuration_template.rb +36 -36
- data/lib/cf_factory/eb/cf_eb_environment.rb +56 -56
- data/lib/cf_factory/eb/cf_eb_option_setting.rb +19 -19
- data/lib/cf_factory/ec2/cf_ebs_volume.rb +56 -56
- data/lib/cf_factory/ec2/cf_ec2_instance.rb +80 -66
- data/lib/cf_factory/ec2/cf_ec2_security_group.rb +42 -42
- data/lib/cf_factory/ec2/cf_ec2_security_group_egress.rb +30 -30
- data/lib/cf_factory/ec2/cf_ec2_security_group_ingress.rb +41 -41
- data/lib/cf_factory/ec2/cf_eip.rb +28 -28
- data/lib/cf_factory/ec2/cf_eip_association.rb +33 -31
- data/lib/cf_factory/ec2/cf_inner_network_interface.rb +26 -0
- data/lib/cf_factory/ec2/cf_network_interface.rb +40 -0
- data/lib/cf_factory/elb/cf_app_cookie_stickiness_policy.rb +17 -17
- data/lib/cf_factory/elb/cf_elb.rb +51 -51
- data/lib/cf_factory/elb/cf_health_check.rb +25 -25
- data/lib/cf_factory/elb/cf_lb_cookie_stickiness_policy.rb +17 -17
- data/lib/cf_factory/elb/cf_listener.rb +28 -28
- data/lib/cf_factory/help/fixes.rb +15 -15
- data/lib/cf_factory/help/ip_mask.rb +167 -167
- data/lib/cf_factory/help/template_validation.rb +30 -30
- data/lib/cf_factory/iam/cf_iam_access_key.rb +34 -34
- data/lib/cf_factory/iam/cf_iam_group.rb +32 -32
- data/lib/cf_factory/iam/cf_iam_instance_profile.rb +32 -32
- data/lib/cf_factory/iam/cf_iam_policy.rb +20 -20
- data/lib/cf_factory/iam/cf_iam_role.rb +58 -58
- data/lib/cf_factory/iam/cf_iam_statement.rb +25 -25
- data/lib/cf_factory/iam/cf_iam_user.rb +36 -36
- data/lib/cf_factory/iam/cf_policy_document.rb +21 -21
- data/lib/cf_factory/modules/base_vpc.rb +63 -63
- data/lib/cf_factory/rds/cf_rds_instance.rb +55 -55
- data/lib/cf_factory/rds/cf_rds_security_group.rb +35 -35
- data/lib/cf_factory/rds/cf_rds_security_group_ingress.rb +31 -31
- data/lib/cf_factory/rds/cf_rds_subnet_group.rb +31 -31
- data/lib/cf_factory/route53/cf_elb_alias_target.rb +23 -23
- data/lib/cf_factory/route53/cf_record_set.rb +63 -63
- data/lib/cf_factory/route53/cf_route53_record_set.rb +63 -63
- data/lib/cf_factory/route53/cf_route53_record_set_group.rb +44 -44
- data/lib/cf_factory/s3/cf_s3_bucket.rb +34 -34
- data/lib/cf_factory/s3/cf_web_site_config.rb +26 -26
- data/lib/cf_factory/sqs/cf_sqs_queue.rb +28 -28
- data/lib/cf_factory/vpc/cf_attach_gateway.rb +30 -30
- data/lib/cf_factory/vpc/cf_internet_gateway.rb +32 -32
- data/lib/cf_factory/vpc/cf_network_acl.rb +41 -41
- data/lib/cf_factory/vpc/cf_network_acl_association.rb +26 -26
- data/lib/cf_factory/vpc/cf_network_acl_entry.rb +39 -39
- data/lib/cf_factory/vpc/cf_route.rb +45 -45
- data/lib/cf_factory/vpc/cf_route_table.rb +43 -43
- data/lib/cf_factory/vpc/cf_route_table_association.rb +26 -26
- data/lib/cf_factory/vpc/cf_subnet.rb +50 -50
- data/lib/cf_factory/vpc/cf_vpc.rb +66 -66
- data/lib/cf_factory.rb +12 -12
- metadata +120 -91
data/examples/ra_web_hosting.rb
CHANGED
@@ -1,148 +1,148 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
|
3
|
-
require 'cf_factory'
|
4
|
-
|
5
|
-
# CloudFormation template for Atraveo. 2-Tiered web-application with load-balancing.
|
6
|
-
cf = CfFactory::CfMain.new("Reference Architecture Web-Hosting")
|
7
|
-
|
8
|
-
####### input parameters
|
9
|
-
hosted_zone_id = "ZSSFB90C439AA"
|
10
|
-
hosted_zone_name = "dezidr.com"
|
11
|
-
|
12
|
-
#ami_id = "ami-c6699baf"
|
13
|
-
#ami_id = "ami-e96bdf80" #eu-west NAT instance
|
14
|
-
ami_id = "ami-e96bdf80" #us-east web-server returning something
|
15
|
-
|
16
|
-
param_hosted_zone = CfFactory::CfParameter.new("HostedZoneId", "Needs an existing hosted zone in Route53 to be configured", "String", {"Default" => hosted_zone_id})
|
17
|
-
cf.add_parameter(param_hosted_zone)
|
18
|
-
param_app_server_ami = CfFactory::CfParameter.new("AppServerAmi", "AMI of App-Server", "String", {"Default" => ami_id})
|
19
|
-
cf.add_parameter(param_app_server_ami)
|
20
|
-
param_app_server_key = CfFactory::CfParameter.new("AppServerKey", "Key used to start App-Server", "String")
|
21
|
-
cf.add_parameter(param_app_server_key)
|
22
|
-
param_app_port = CfFactory::CfParameter.new("AppPort", "Port of the Web/App-Servers", "Number", {"Default" => "8080"})
|
23
|
-
cf.add_parameter(param_app_port)
|
24
|
-
param_db_user = CfFactory::CfParameter.new("MasterUserName", "Name of the master user name of the DB", "String", {"Default" => "masteruser"})
|
25
|
-
cf.add_parameter(param_db_user)
|
26
|
-
param_db_pw = CfFactory::CfParameter.new("MasterPassword", "Password of the master user of the DB", "String")
|
27
|
-
cf.add_parameter(param_db_pw)
|
28
|
-
|
29
|
-
zone = "us-east"
|
30
|
-
|
31
|
-
####### mappings
|
32
|
-
|
33
|
-
####### resources
|
34
|
-
|
35
|
-
#ebs test
|
36
|
-
ebs = CfFactory::CfEbsVolume.create_normal("MyEbs",CfFactory::CfHelper.az_in_region(az_id = "b"), 5)
|
37
|
-
cf.add_resource(ebs)
|
38
|
-
|
39
|
-
s3_bucket = CfFactory::CfS3Bucket.new("MyS3Bucket")
|
40
|
-
cf.add_resource(s3_bucket)
|
41
|
-
s3_log_bucket = CfFactory::CfS3Bucket.new("MyS3LogBucket")
|
42
|
-
s3_log_bucket.set_deletion_policy("Delete")
|
43
|
-
cf.add_resource(s3_log_bucket)
|
44
|
-
|
45
|
-
#security groups
|
46
|
-
# ELB security groups apparently only available for VPC
|
47
|
-
#elb_sec_group = CfEc2SecurityGroup.new("ElbSecurityGroup", "Security Group for ELB")
|
48
|
-
#elb_sec_group.add_ingress_rule(CfEc2SecurityGroupIngress.new("tcp", 80, 80, "0.0.0.0/0"))
|
49
|
-
#elb_sec_group.add_ingress_rule(CfEc2SecurityGroupIngress.new("tcp", 443, 443, "0.0.0.0/0"))
|
50
|
-
#cf.add_resource(elb_sec_group)
|
51
|
-
|
52
|
-
#elb
|
53
|
-
#health_check_string = "HTTP:#{param_app_port.generate_ref()}/index.html"
|
54
|
-
health_check_string = "HTTP:80/index.html"
|
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")],
|
58
|
-
#:security_groups => [elb_sec_group], #only for VPC based ELBs
|
59
|
-
:availability_zones => CfFactory::CfHelper.availability_zones()
|
60
|
-
}
|
61
|
-
)
|
62
|
-
cf.add_resource(elb)
|
63
|
-
|
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")
|
67
|
-
app_sec_group.add_ingress_rule(ir1)
|
68
|
-
cf.add_resource(app_sec_group)
|
69
|
-
|
70
|
-
rds_sec_group = CfFactory::CfRdsSecurityGroup.new("RdsSecurityGroup","Security Group for RDS")
|
71
|
-
ir = CfFactory::CfRdsSecurityGroupIngress.new(nil,app_sec_group)
|
72
|
-
ir.set_use_sg_id(false)
|
73
|
-
rds_sec_group.add_rule(ir)
|
74
|
-
cf.add_resource(rds_sec_group)
|
75
|
-
|
76
|
-
#rds
|
77
|
-
rds_endpoint= "rdsendpoint"
|
78
|
-
options = {:multi_az => true, :security_groups => [rds_sec_group]}
|
79
|
-
rds_instance = CfFactory::CfRdsInstance.new("MyDatabase",5,"MySql","db.t1.micro",param_db_user.generate_ref(), param_db_pw.generate_ref, options)
|
80
|
-
cf.add_resource(rds_instance)
|
81
|
-
rds_endpoint = rds_instance.retrieve_attribute("Endpoint.Address")
|
82
|
-
|
83
|
-
#iam-role to be able to read meta-data
|
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]})
|
87
|
-
cf.add_resource(iam_role)
|
88
|
-
|
89
|
-
#auto-scaling group
|
90
|
-
launch_config = CfFactory::CfAsLaunchConfig.new("AppServerLaunchConfig", ami_id, "t1.micro", {:security_groups => [app_sec_group], :user_data => rds_endpoint})
|
91
|
-
cf.add_resource(launch_config)
|
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})
|
94
|
-
cf.add_resource(as_group)
|
95
|
-
as_up_scaling_policy = CfFactory::CfAsScalingPolicy.new("MyUpscalePolicy",as_group,"ChangeInCapacity","1",{:cooldown => 300})
|
96
|
-
cf.add_resource(as_up_scaling_policy)
|
97
|
-
as_down_scaling_policy = CfFactory::CfAsScalingPolicy.new("MyDownscalePolicy",as_group,"ChangeInCapacity","-1",{:cooldown => 300})
|
98
|
-
cf.add_resource(as_down_scaling_policy)
|
99
|
-
as_up_alarm = CfFactory::CfCloudWatchAlarm.new("MyUpAlarm",CfFactory::CfCloudWatchAlarm::GREATER_THAN_OR_EQUAL_TO_THRESHOLD, "3", "CPUUtilization","AWS/EC2",
|
100
|
-
"60","Average","80", {:alarm_actions => [as_up_scaling_policy]})
|
101
|
-
as_down_alarm = CfFactory::CfCloudWatchAlarm.new("MyDownAlarm",CfFactory::CfCloudWatchAlarm::LESS_THAN_THRESHOLD, "3", "CPUUtilization","AWS/EC2",
|
102
|
-
"60","Average","30", {:alarm_actions => [as_down_scaling_policy]})
|
103
|
-
cf.add_resource(as_up_alarm)
|
104
|
-
cf.add_resource(as_down_alarm)
|
105
|
-
|
106
|
-
#cloudfront
|
107
|
-
# distribution with multiple origins, one for S3, one for the ELB
|
108
|
-
#define origins
|
109
|
-
elb_origin = CfFactory::CfOrigin.create_elb_origin(elb)
|
110
|
-
s3_origin = CfFactory::CfOrigin.create_s3_origin(s3_bucket)
|
111
|
-
origins = [elb_origin, s3_origin]
|
112
|
-
#define cache behaviors for origins
|
113
|
-
default_cache_behavior = CfFactory::CfDefaultCacheBehavior.create_basic(elb_origin.id)
|
114
|
-
cache_behaviors = [
|
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)
|
117
|
-
]
|
118
|
-
#tie everything together
|
119
|
-
cname_endpoint = "cached-elb-#{(Random.new.rand*100000).to_i}.dezidr.com"
|
120
|
-
logging = CfFactory::CfLogging.new(s3_log_bucket,"log-") #activate logging
|
121
|
-
cf_distribution = CfFactory::CfCloudfrontDistribution.create_multi_origin_distribution("MyDistribution", origins,
|
122
|
-
default_cache_behavior, cache_behaviors, {:logging => logging, :aliases => [cname_endpoint]})
|
123
|
-
cf.add_resource(cf_distribution)
|
124
|
-
|
125
|
-
#route53
|
126
|
-
cloudfront_dns = cf_distribution.retrieve_attribute("DomainName")
|
127
|
-
cname = CfFactory::CfRoute53RecordSet.new("CnameRecord", "#{cname_endpoint}", "CNAME", {:ttl => 1, :resource_records => [cloudfront_dns], :hosted_zone_id => hosted_zone_id})
|
128
|
-
cf.add_resource(cname)
|
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})
|
130
|
-
cf.add_resource(elb_alias)
|
131
|
-
|
132
|
-
####### output parameters
|
133
|
-
elb_output = CfFactory::CfOutput.new("ElbEndpoint","Endpoint of the ELB",elb.retrieve_attribute("DNSName"))
|
134
|
-
cf.add_output(elb_output)
|
135
|
-
cloudfront_domain = CfFactory::CfOutput.new("CloudfrontDomain", "Endpoint of the CloudFront distribution", cf_distribution.retrieve_attribute("DomainName"))
|
136
|
-
cf.add_output(cloudfront_domain)
|
137
|
-
|
138
|
-
cf_json = cf.generate
|
139
|
-
puts cf_json
|
140
|
-
|
141
|
-
config_options = YAML.load_file("aws_config.yml")
|
142
|
-
config_options["cloud_formation_endpoint"] = "cloudformation.us-east-1.amazonaws.com"
|
143
|
-
puts config_options.inspect
|
144
|
-
validator = CfFactory::TemplateValidation.new(cf_json, config_options)
|
145
|
-
validator.validate()
|
146
|
-
#validator.apply({"AppServerAmi" => ami_id, "AppServerKey" => "majung", "AppPort" => "80", "MasterUserName" => "iamauser", "MasterPassword" => "abcd1234"})
|
147
|
-
|
148
|
-
#puts "the reference for the VPC : #{vpc.generate_ref}"
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'cf_factory'
|
4
|
+
|
5
|
+
# CloudFormation template for Atraveo. 2-Tiered web-application with load-balancing.
|
6
|
+
cf = CfFactory::CfMain.new("Reference Architecture Web-Hosting")
|
7
|
+
|
8
|
+
####### input parameters
|
9
|
+
hosted_zone_id = "ZSSFB90C439AA"
|
10
|
+
hosted_zone_name = "dezidr.com"
|
11
|
+
|
12
|
+
#ami_id = "ami-c6699baf"
|
13
|
+
#ami_id = "ami-e96bdf80" #eu-west NAT instance
|
14
|
+
ami_id = "ami-e96bdf80" #us-east web-server returning something
|
15
|
+
|
16
|
+
param_hosted_zone = CfFactory::CfParameter.new("HostedZoneId", "Needs an existing hosted zone in Route53 to be configured", "String", {"Default" => hosted_zone_id})
|
17
|
+
cf.add_parameter(param_hosted_zone)
|
18
|
+
param_app_server_ami = CfFactory::CfParameter.new("AppServerAmi", "AMI of App-Server", "String", {"Default" => ami_id})
|
19
|
+
cf.add_parameter(param_app_server_ami)
|
20
|
+
param_app_server_key = CfFactory::CfParameter.new("AppServerKey", "Key used to start App-Server", "String")
|
21
|
+
cf.add_parameter(param_app_server_key)
|
22
|
+
param_app_port = CfFactory::CfParameter.new("AppPort", "Port of the Web/App-Servers", "Number", {"Default" => "8080"})
|
23
|
+
cf.add_parameter(param_app_port)
|
24
|
+
param_db_user = CfFactory::CfParameter.new("MasterUserName", "Name of the master user name of the DB", "String", {"Default" => "masteruser"})
|
25
|
+
cf.add_parameter(param_db_user)
|
26
|
+
param_db_pw = CfFactory::CfParameter.new("MasterPassword", "Password of the master user of the DB", "String")
|
27
|
+
cf.add_parameter(param_db_pw)
|
28
|
+
|
29
|
+
zone = "us-east"
|
30
|
+
|
31
|
+
####### mappings
|
32
|
+
|
33
|
+
####### resources
|
34
|
+
|
35
|
+
#ebs test
|
36
|
+
ebs = CfFactory::CfEbsVolume.create_normal("MyEbs",CfFactory::CfHelper.az_in_region(az_id = "b"), 5)
|
37
|
+
cf.add_resource(ebs)
|
38
|
+
|
39
|
+
s3_bucket = CfFactory::CfS3Bucket.new("MyS3Bucket")
|
40
|
+
cf.add_resource(s3_bucket)
|
41
|
+
s3_log_bucket = CfFactory::CfS3Bucket.new("MyS3LogBucket")
|
42
|
+
s3_log_bucket.set_deletion_policy("Delete")
|
43
|
+
cf.add_resource(s3_log_bucket)
|
44
|
+
|
45
|
+
#security groups
|
46
|
+
# ELB security groups apparently only available for VPC
|
47
|
+
#elb_sec_group = CfEc2SecurityGroup.new("ElbSecurityGroup", "Security Group for ELB")
|
48
|
+
#elb_sec_group.add_ingress_rule(CfEc2SecurityGroupIngress.new("tcp", 80, 80, "0.0.0.0/0"))
|
49
|
+
#elb_sec_group.add_ingress_rule(CfEc2SecurityGroupIngress.new("tcp", 443, 443, "0.0.0.0/0"))
|
50
|
+
#cf.add_resource(elb_sec_group)
|
51
|
+
|
52
|
+
#elb
|
53
|
+
#health_check_string = "HTTP:#{param_app_port.generate_ref()}/index.html"
|
54
|
+
health_check_string = "HTTP:80/index.html"
|
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")],
|
58
|
+
#:security_groups => [elb_sec_group], #only for VPC based ELBs
|
59
|
+
:availability_zones => CfFactory::CfHelper.availability_zones()
|
60
|
+
}
|
61
|
+
)
|
62
|
+
cf.add_resource(elb)
|
63
|
+
|
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")
|
67
|
+
app_sec_group.add_ingress_rule(ir1)
|
68
|
+
cf.add_resource(app_sec_group)
|
69
|
+
|
70
|
+
rds_sec_group = CfFactory::CfRdsSecurityGroup.new("RdsSecurityGroup","Security Group for RDS")
|
71
|
+
ir = CfFactory::CfRdsSecurityGroupIngress.new(nil,app_sec_group)
|
72
|
+
ir.set_use_sg_id(false)
|
73
|
+
rds_sec_group.add_rule(ir)
|
74
|
+
cf.add_resource(rds_sec_group)
|
75
|
+
|
76
|
+
#rds
|
77
|
+
rds_endpoint= "rdsendpoint"
|
78
|
+
options = {:multi_az => true, :security_groups => [rds_sec_group]}
|
79
|
+
rds_instance = CfFactory::CfRdsInstance.new("MyDatabase",5,"MySql","db.t1.micro",param_db_user.generate_ref(), param_db_pw.generate_ref, options)
|
80
|
+
cf.add_resource(rds_instance)
|
81
|
+
rds_endpoint = rds_instance.retrieve_attribute("Endpoint.Address")
|
82
|
+
|
83
|
+
#iam-role to be able to read meta-data
|
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]})
|
87
|
+
cf.add_resource(iam_role)
|
88
|
+
|
89
|
+
#auto-scaling group
|
90
|
+
launch_config = CfFactory::CfAsLaunchConfig.new("AppServerLaunchConfig", ami_id, "t1.micro", {:security_groups => [app_sec_group], :user_data => rds_endpoint})
|
91
|
+
cf.add_resource(launch_config)
|
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})
|
94
|
+
cf.add_resource(as_group)
|
95
|
+
as_up_scaling_policy = CfFactory::CfAsScalingPolicy.new("MyUpscalePolicy",as_group,"ChangeInCapacity","1",{:cooldown => 300})
|
96
|
+
cf.add_resource(as_up_scaling_policy)
|
97
|
+
as_down_scaling_policy = CfFactory::CfAsScalingPolicy.new("MyDownscalePolicy",as_group,"ChangeInCapacity","-1",{:cooldown => 300})
|
98
|
+
cf.add_resource(as_down_scaling_policy)
|
99
|
+
as_up_alarm = CfFactory::CfCloudWatchAlarm.new("MyUpAlarm",CfFactory::CfCloudWatchAlarm::GREATER_THAN_OR_EQUAL_TO_THRESHOLD, "3", "CPUUtilization","AWS/EC2",
|
100
|
+
"60","Average","80", {:alarm_actions => [as_up_scaling_policy]})
|
101
|
+
as_down_alarm = CfFactory::CfCloudWatchAlarm.new("MyDownAlarm",CfFactory::CfCloudWatchAlarm::LESS_THAN_THRESHOLD, "3", "CPUUtilization","AWS/EC2",
|
102
|
+
"60","Average","30", {:alarm_actions => [as_down_scaling_policy]})
|
103
|
+
cf.add_resource(as_up_alarm)
|
104
|
+
cf.add_resource(as_down_alarm)
|
105
|
+
|
106
|
+
#cloudfront
|
107
|
+
# distribution with multiple origins, one for S3, one for the ELB
|
108
|
+
#define origins
|
109
|
+
elb_origin = CfFactory::CfOrigin.create_elb_origin(elb)
|
110
|
+
s3_origin = CfFactory::CfOrigin.create_s3_origin(s3_bucket)
|
111
|
+
origins = [elb_origin, s3_origin]
|
112
|
+
#define cache behaviors for origins
|
113
|
+
default_cache_behavior = CfFactory::CfDefaultCacheBehavior.create_basic(elb_origin.id)
|
114
|
+
cache_behaviors = [
|
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)
|
117
|
+
]
|
118
|
+
#tie everything together
|
119
|
+
cname_endpoint = "cached-elb-#{(Random.new.rand*100000).to_i}.dezidr.com"
|
120
|
+
logging = CfFactory::CfLogging.new(s3_log_bucket,"log-") #activate logging
|
121
|
+
cf_distribution = CfFactory::CfCloudfrontDistribution.create_multi_origin_distribution("MyDistribution", origins,
|
122
|
+
default_cache_behavior, cache_behaviors, {:logging => logging, :aliases => [cname_endpoint]})
|
123
|
+
cf.add_resource(cf_distribution)
|
124
|
+
|
125
|
+
#route53
|
126
|
+
cloudfront_dns = cf_distribution.retrieve_attribute("DomainName")
|
127
|
+
cname = CfFactory::CfRoute53RecordSet.new("CnameRecord", "#{cname_endpoint}", "CNAME", {:ttl => 1, :resource_records => [cloudfront_dns], :hosted_zone_id => hosted_zone_id})
|
128
|
+
cf.add_resource(cname)
|
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})
|
130
|
+
cf.add_resource(elb_alias)
|
131
|
+
|
132
|
+
####### output parameters
|
133
|
+
elb_output = CfFactory::CfOutput.new("ElbEndpoint","Endpoint of the ELB",elb.retrieve_attribute("DNSName"))
|
134
|
+
cf.add_output(elb_output)
|
135
|
+
cloudfront_domain = CfFactory::CfOutput.new("CloudfrontDomain", "Endpoint of the CloudFront distribution", cf_distribution.retrieve_attribute("DomainName"))
|
136
|
+
cf.add_output(cloudfront_domain)
|
137
|
+
|
138
|
+
cf_json = cf.generate
|
139
|
+
puts cf_json
|
140
|
+
|
141
|
+
config_options = YAML.load_file("aws_config.yml")
|
142
|
+
config_options["cloud_formation_endpoint"] = "cloudformation.us-east-1.amazonaws.com"
|
143
|
+
puts config_options.inspect
|
144
|
+
validator = CfFactory::TemplateValidation.new(cf_json, config_options)
|
145
|
+
validator.validate()
|
146
|
+
#validator.apply({"AppServerAmi" => ami_id, "AppServerKey" => "majung", "AppPort" => "80", "MasterUserName" => "iamauser", "MasterPassword" => "abcd1234"})
|
147
|
+
|
148
|
+
#puts "the reference for the VPC : #{vpc.generate_ref}"
|
@@ -1,35 +1,35 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
|
3
|
-
require 'cf_factory'
|
4
|
-
|
5
|
-
# CloudFormation template for Atraveo. 2-Tiered web-application with load-balancing.
|
6
|
-
cf = CfFactory::CfMain.new("S3 Bucket with CloudFront distribution")
|
7
|
-
|
8
|
-
####### input parameters
|
9
|
-
|
10
|
-
####### mappings
|
11
|
-
|
12
|
-
####### resources
|
13
|
-
|
14
|
-
s3_bucket = CfFactory::CfS3Bucket.new("OriginBucket")
|
15
|
-
cf.add_resource(s3_bucket)
|
16
|
-
s3_log_bucket = CfFactory::CfS3Bucket.new("LogBucket")
|
17
|
-
|
18
|
-
#cloudfront
|
19
|
-
logging = CfFactory::CfLogging.new(s3_bucket,"MyDistribution")
|
20
|
-
options = {:logging => logging}
|
21
|
-
cloudfront_distribution = CfFactory::CfCloudfrontDistribution.create_s3_distribution("MyS3Distribution",s3_bucket)
|
22
|
-
cf.add_resource(cloudfront_distribution)
|
23
|
-
|
24
|
-
####### output parameters
|
25
|
-
s3_domain = CfFactory::CfOutput.new("S3Domain","Domain name of S3 bucket",s3_bucket.retrieve_attribute("DomainName"))
|
26
|
-
cf.add_output(s3_domain)
|
27
|
-
cloudfront_domain = CfFactory::CfOutput.new("CloudfrontDomain", "Endpoint of the CloudFront distribution", cloudfront_distribution.retrieve_attribute("DomainName"))
|
28
|
-
cf.add_output(cloudfront_domain)
|
29
|
-
|
30
|
-
cf_json = cf.generate
|
31
|
-
puts cf_json
|
32
|
-
|
33
|
-
config_options = YAML.load_file("aws_config.yml")
|
34
|
-
validator = CfFactory::TemplateValidation.new(cf_json, config_options)
|
35
|
-
validator.validate()
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'cf_factory'
|
4
|
+
|
5
|
+
# CloudFormation template for Atraveo. 2-Tiered web-application with load-balancing.
|
6
|
+
cf = CfFactory::CfMain.new("S3 Bucket with CloudFront distribution")
|
7
|
+
|
8
|
+
####### input parameters
|
9
|
+
|
10
|
+
####### mappings
|
11
|
+
|
12
|
+
####### resources
|
13
|
+
|
14
|
+
s3_bucket = CfFactory::CfS3Bucket.new("OriginBucket")
|
15
|
+
cf.add_resource(s3_bucket)
|
16
|
+
s3_log_bucket = CfFactory::CfS3Bucket.new("LogBucket")
|
17
|
+
|
18
|
+
#cloudfront
|
19
|
+
logging = CfFactory::CfLogging.new(s3_bucket,"MyDistribution")
|
20
|
+
options = {:logging => logging}
|
21
|
+
cloudfront_distribution = CfFactory::CfCloudfrontDistribution.create_s3_distribution("MyS3Distribution",s3_bucket)
|
22
|
+
cf.add_resource(cloudfront_distribution)
|
23
|
+
|
24
|
+
####### output parameters
|
25
|
+
s3_domain = CfFactory::CfOutput.new("S3Domain","Domain name of S3 bucket",s3_bucket.retrieve_attribute("DomainName"))
|
26
|
+
cf.add_output(s3_domain)
|
27
|
+
cloudfront_domain = CfFactory::CfOutput.new("CloudfrontDomain", "Endpoint of the CloudFront distribution", cloudfront_distribution.retrieve_attribute("DomainName"))
|
28
|
+
cf.add_output(cloudfront_domain)
|
29
|
+
|
30
|
+
cf_json = cf.generate
|
31
|
+
puts cf_json
|
32
|
+
|
33
|
+
config_options = YAML.load_file("aws_config.yml")
|
34
|
+
validator = CfFactory::TemplateValidation.new(cf_json, config_options)
|
35
|
+
validator.validate()
|
data/examples/test_vpc.rb
CHANGED
@@ -1,61 +1,61 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
|
3
|
-
require 'cf_factory'
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
vpc
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
route_table.add_route(
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
#elb
|
43
|
-
#
|
44
|
-
# :
|
45
|
-
#
|
46
|
-
#
|
47
|
-
|
48
|
-
|
49
|
-
output
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
-
|
60
|
-
|
61
|
-
#puts "the reference for the VPC : #{vpc.generate_ref}"
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'cf_factory'
|
4
|
+
require 'cf_factory/base/cf_main'
|
5
|
+
|
6
|
+
cf = CfFactory::CfMain.new("Bla bla bla")
|
7
|
+
####### input parameters
|
8
|
+
parameter = CfFactory::CfParameter.new("KeyName", "Name of the key", "String", {"Default" => "majung"})
|
9
|
+
cf.add_parameter(parameter)
|
10
|
+
parameter2 = CfFactory::CfParameter.new("SecurityGroup", "Name of the security group", "String", {"Default" => "Blubber"})
|
11
|
+
cf.add_parameter(parameter2)
|
12
|
+
|
13
|
+
####### mappings
|
14
|
+
mapping = CfFactory::CfMapping.new("Default","AMI",{"us-east-1" => "ami-c6699baf", "us-west-2" => "ami-52ff7262"})
|
15
|
+
cf.add_mapping(mapping)
|
16
|
+
|
17
|
+
####### resources
|
18
|
+
#vpc
|
19
|
+
vpc = CfFactory::CfVpc.new("10.10.0.0/16")
|
20
|
+
cf.add_vpc(vpc)
|
21
|
+
igw = CfFactory::CfInternetGateway.new("MyInternetGateway", vpc)
|
22
|
+
vpc.add_internet_gateway(igw)
|
23
|
+
route_table = CfFactory::CfRouteTable.new("MyRouteTable")
|
24
|
+
vpc.add_route_table(route_table)
|
25
|
+
route1 = CfFactory::CfRoute.new("MyRoute1", "88.44.22.11/32", igw)
|
26
|
+
route2 = CfFactory::CfRoute.new("MyRoute2", "188.144.122.111/32", igw)
|
27
|
+
route_table.add_route(route1)
|
28
|
+
route_table.add_route(route2)
|
29
|
+
|
30
|
+
network_acl = CfFactory::CfNetworkAcl.new("MyAcl1")
|
31
|
+
vpc.add_network_acl(network_acl)
|
32
|
+
network_acl_entry = CfFactory::CfNetworkAclEntry.new("Acl1", "110", "6", "ALLOW", false, "0.0.0.0/0", 80, 80)
|
33
|
+
network_acl.add_network_acl_entry(network_acl_entry)
|
34
|
+
|
35
|
+
subnet1 = CfFactory::CfSubnet.new("WebTier1", "10.10.0.0/24", "eu-west-1a", route_table, network_acl)
|
36
|
+
vpc.add_subnet(subnet1)
|
37
|
+
subnet2 = CfFactory::CfSubnet.new("AppTier1", "10.10.1.0/24", "eu-west-1a", route_table, network_acl)
|
38
|
+
vpc.add_subnet(subnet2)
|
39
|
+
subnet3 = CfFactory::CfSubnet.new("DbTier1", "10.10.2.0/24", "eu-west-1a", route_table, network_acl)
|
40
|
+
vpc.add_subnet(subnet3)
|
41
|
+
|
42
|
+
#elb
|
43
|
+
#elb = CfElb.new("MyElb", {
|
44
|
+
# :availability_zones => "eu-west-1",
|
45
|
+
# :app_cookie_stickiness_policy => CfAppCookieStickinessPolicy.new("cookie-name","policy bla")})
|
46
|
+
#cf.add_elb(elb)
|
47
|
+
#puts elb.get_cf_properties()
|
48
|
+
|
49
|
+
####### output parameters
|
50
|
+
output = CfFactory::CfOutput.new("VpcId", "Id of the VPC", vpc.generate_ref())
|
51
|
+
cf.add_output(output)
|
52
|
+
|
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
|
+
|
60
|
+
|
61
|
+
#puts "the reference for the VPC : #{vpc.generate_ref}"
|