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
@@ -1,100 +1,100 @@
|
|
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("CloudFront with ELB as origin with dynamic content")
|
7
|
-
app_port = 8080
|
8
|
-
key_name = "default"
|
9
|
-
app_server_ami = "ami-c6699baf"
|
10
|
-
spot_price = "0.02"
|
11
|
-
|
12
|
-
####### input parameters
|
13
|
-
param_app_server_ami = CfFactory::CfParameter.new("AppServerAmi", "AMI of App-Server", "String")
|
14
|
-
cf.add_parameter(param_app_server_ami)
|
15
|
-
param_app_server_key = CfFactory::CfParameter.new("AppServerKey", "Key used to start App-Server", "String")
|
16
|
-
cf.add_parameter(param_app_server_key)
|
17
|
-
param_app_port = CfFactory::CfParameter.new("AppPort", "Port of the Web/App-Servers", "Number", {"Default" => "8080"})
|
18
|
-
cf.add_parameter(param_app_port)
|
19
|
-
|
20
|
-
zone = "us-east"
|
21
|
-
|
22
|
-
####### mappings
|
23
|
-
|
24
|
-
####### resources
|
25
|
-
|
26
|
-
#VPC/subnets: all public to be able to be able to connect the instances by adding an EIP
|
27
|
-
#VPC, IGW, and route tables
|
28
|
-
vpc = CfFactory::CfVpc.new("10.10.0.0/16")
|
29
|
-
cf.add_vpc(vpc)
|
30
|
-
igw = CfFactory::CfInternetGateway.new("MyInternetGateway", vpc)
|
31
|
-
vpc.add_internet_gateway(igw)
|
32
|
-
public_route_table = CfFactory::CfRouteTable.new("InternetRouteTable")
|
33
|
-
igw_route = CfFactory::CfRoute.new("IgwRoute", "0.0.0.0/0", igw)
|
34
|
-
public_route_table.add_route(igw_route)
|
35
|
-
vpc.add_route_table(public_route_table)
|
36
|
-
|
37
|
-
# subnets
|
38
|
-
subnet_elb_a = CfFactory::CfSubnet.new("SubnetElbA", "10.10.1.0/24", "#{zone}-1c", public_route_table)
|
39
|
-
vpc.add_subnet(subnet_elb_a)
|
40
|
-
subnet_elb_b = CfFactory::CfSubnet.new("SubnetElbB", "10.10.2.0/24", "#{zone}-1b", public_route_table)
|
41
|
-
vpc.add_subnet(subnet_elb_b)
|
42
|
-
subnet_web_a = CfFactory::CfSubnet.new("SubnetWebA", "10.10.3.0/24", "#{zone}-1c", public_route_table)
|
43
|
-
vpc.add_subnet(subnet_web_a)
|
44
|
-
subnet_web_b = CfFactory::CfSubnet.new("SubnetWebB", "10.10.4.0/24", "#{zone}-1b", public_route_table)
|
45
|
-
vpc.add_subnet(subnet_web_b)
|
46
|
-
|
47
|
-
#security groups
|
48
|
-
elb_security_group_name = "ElbSecurityGroup"
|
49
|
-
elb_sec_group = CfFactory::CfEc2SecurityGroup.new(elb_security_group_name, "Group for ELB", vpc)
|
50
|
-
elb_sec_group.add_ingress_rule(CfFactory::CfEc2SecurityGroupIngress.new("tcp", 80, 80, "0.0.0.0/0"))
|
51
|
-
elb_sec_group.add_ingress_rule(CfFactory::CfEc2SecurityGroupIngress.new("tcp", 443, 443, "0.0.0.0/0"))
|
52
|
-
cf.add_resource(elb_sec_group)
|
53
|
-
|
54
|
-
app_security_group_name = "AppSecurityGroup"
|
55
|
-
app_sec_group = CfFactory::CfEc2SecurityGroup.new(app_security_group_name, "Group for web and app", vpc)
|
56
|
-
app_sec_group.add_ingress_rule(CfFactory::CfEc2SecurityGroupIngress.new("tcp", 22, 22, "0.0.0.0/0"))
|
57
|
-
app_sec_group.add_ingress_rule(CfFactory::CfEc2SecurityGroupIngress.new("tcp", param_app_port.generate_ref(), param_app_port.generate_ref(), nil, elb_sec_group))
|
58
|
-
cf.add_resource(app_sec_group)
|
59
|
-
|
60
|
-
#application servers (one in each region)
|
61
|
-
options = {}
|
62
|
-
instance_a = CfFactory::CfEc2Instance.new("InstanceA",param_app_server_ami.generate_ref, "t1.micro", {:subnet => subnet_web_a, :vpc_security_groups => [app_sec_group]})
|
63
|
-
instance_b = CfFactory::CfEc2Instance.new("InstanceB",param_app_server_ami.generate_ref, "t1.micro", {:subnet => subnet_web_b, :vpc_security_groups => [app_sec_group]})
|
64
|
-
cf.add_resource(instance_a)
|
65
|
-
cf.add_resource(instance_b)
|
66
|
-
|
67
|
-
#elb
|
68
|
-
#health_check_string = "HTTP:#{param_app_port.generate_ref()}/index.html"
|
69
|
-
health_check_string = "HTTP:80/index.html"
|
70
|
-
elb = CfFactory::CfElb.new("MyLoadBalancer", {
|
71
|
-
:subnets => [subnet_elb_a, subnet_elb_b],
|
72
|
-
#:app_cookie_stickiness_policy => [CfAppCookieStickinessPolicy.new("cookiename","policybla")],
|
73
|
-
:health_check => CfFactory::CfHealthCheck.new("3","60", health_check_string,"10","2"),
|
74
|
-
:listeners => [CfFactory::CfListener.new(param_app_port.generate_ref(),"http","80","http")],
|
75
|
-
:security_groups => [elb_sec_group],
|
76
|
-
:instances => [instance_a, instance_b]
|
77
|
-
}
|
78
|
-
)
|
79
|
-
cf.add_resource(elb)
|
80
|
-
|
81
|
-
#cloudfront
|
82
|
-
origin = CfFactory::CfCustomOriginConfig.new("http-only",:http_port => 80)
|
83
|
-
origin_config = CfFactory::CfOrigin.new(elb.retrieve_attribute("DNSName") ,"CF001", origin)
|
84
|
-
default_cache_behavior = CfFactory::CfDefaultCacheBehavior.new(origin_config.id,CfFactory::CfForwardedValues.new(true),"allow-all",{:min_ttl => 0})
|
85
|
-
distribution_details = CfFactory::CfDistributionConfig.new([origin_config],default_cache_behavior,true)
|
86
|
-
cloudfront_distribution = CfFactory::CfCloudfrontDistribution.new("MyDistribution",distribution_details)
|
87
|
-
cf.add_resource(cloudfront_distribution)
|
88
|
-
|
89
|
-
####### output parameters
|
90
|
-
elb_output = CfFactory::CfOutput.new("ElbEndpoint","Endpoint of the ELB",elb.retrieve_attribute("DNSName"))
|
91
|
-
cf.add_output(elb_output)
|
92
|
-
cloudfront_domain = CfFactory::CfOutput.new("CloudfrontDomain", "Endpoint of the CloudFront distribution", cloudfront_distribution.retrieve_attribute("DomainName"))
|
93
|
-
cf.add_output(cloudfront_domain)
|
94
|
-
|
95
|
-
cf_json = cf.generate
|
96
|
-
puts cf_json
|
97
|
-
|
98
|
-
config_options = YAML.load_file("aws_config.yml")
|
99
|
-
validator = CfFactory::TemplateValidation.new(cf_json, config_options)
|
100
|
-
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("CloudFront with ELB as origin with dynamic content")
|
7
|
+
app_port = 8080
|
8
|
+
key_name = "default"
|
9
|
+
app_server_ami = "ami-c6699baf"
|
10
|
+
spot_price = "0.02"
|
11
|
+
|
12
|
+
####### input parameters
|
13
|
+
param_app_server_ami = CfFactory::CfParameter.new("AppServerAmi", "AMI of App-Server", "String")
|
14
|
+
cf.add_parameter(param_app_server_ami)
|
15
|
+
param_app_server_key = CfFactory::CfParameter.new("AppServerKey", "Key used to start App-Server", "String")
|
16
|
+
cf.add_parameter(param_app_server_key)
|
17
|
+
param_app_port = CfFactory::CfParameter.new("AppPort", "Port of the Web/App-Servers", "Number", {"Default" => "8080"})
|
18
|
+
cf.add_parameter(param_app_port)
|
19
|
+
|
20
|
+
zone = "us-east"
|
21
|
+
|
22
|
+
####### mappings
|
23
|
+
|
24
|
+
####### resources
|
25
|
+
|
26
|
+
#VPC/subnets: all public to be able to be able to connect the instances by adding an EIP
|
27
|
+
#VPC, IGW, and route tables
|
28
|
+
vpc = CfFactory::CfVpc.new("10.10.0.0/16")
|
29
|
+
cf.add_vpc(vpc)
|
30
|
+
igw = CfFactory::CfInternetGateway.new("MyInternetGateway", vpc)
|
31
|
+
vpc.add_internet_gateway(igw)
|
32
|
+
public_route_table = CfFactory::CfRouteTable.new("InternetRouteTable")
|
33
|
+
igw_route = CfFactory::CfRoute.new("IgwRoute", "0.0.0.0/0", igw)
|
34
|
+
public_route_table.add_route(igw_route)
|
35
|
+
vpc.add_route_table(public_route_table)
|
36
|
+
|
37
|
+
# subnets
|
38
|
+
subnet_elb_a = CfFactory::CfSubnet.new("SubnetElbA", "10.10.1.0/24", "#{zone}-1c", public_route_table)
|
39
|
+
vpc.add_subnet(subnet_elb_a)
|
40
|
+
subnet_elb_b = CfFactory::CfSubnet.new("SubnetElbB", "10.10.2.0/24", "#{zone}-1b", public_route_table)
|
41
|
+
vpc.add_subnet(subnet_elb_b)
|
42
|
+
subnet_web_a = CfFactory::CfSubnet.new("SubnetWebA", "10.10.3.0/24", "#{zone}-1c", public_route_table)
|
43
|
+
vpc.add_subnet(subnet_web_a)
|
44
|
+
subnet_web_b = CfFactory::CfSubnet.new("SubnetWebB", "10.10.4.0/24", "#{zone}-1b", public_route_table)
|
45
|
+
vpc.add_subnet(subnet_web_b)
|
46
|
+
|
47
|
+
#security groups
|
48
|
+
elb_security_group_name = "ElbSecurityGroup"
|
49
|
+
elb_sec_group = CfFactory::CfEc2SecurityGroup.new(elb_security_group_name, "Group for ELB", vpc)
|
50
|
+
elb_sec_group.add_ingress_rule(CfFactory::CfEc2SecurityGroupIngress.new("tcp", 80, 80, "0.0.0.0/0"))
|
51
|
+
elb_sec_group.add_ingress_rule(CfFactory::CfEc2SecurityGroupIngress.new("tcp", 443, 443, "0.0.0.0/0"))
|
52
|
+
cf.add_resource(elb_sec_group)
|
53
|
+
|
54
|
+
app_security_group_name = "AppSecurityGroup"
|
55
|
+
app_sec_group = CfFactory::CfEc2SecurityGroup.new(app_security_group_name, "Group for web and app", vpc)
|
56
|
+
app_sec_group.add_ingress_rule(CfFactory::CfEc2SecurityGroupIngress.new("tcp", 22, 22, "0.0.0.0/0"))
|
57
|
+
app_sec_group.add_ingress_rule(CfFactory::CfEc2SecurityGroupIngress.new("tcp", param_app_port.generate_ref(), param_app_port.generate_ref(), nil, elb_sec_group))
|
58
|
+
cf.add_resource(app_sec_group)
|
59
|
+
|
60
|
+
#application servers (one in each region)
|
61
|
+
options = {}
|
62
|
+
instance_a = CfFactory::CfEc2Instance.new("InstanceA",param_app_server_ami.generate_ref, "t1.micro", {:subnet => subnet_web_a, :vpc_security_groups => [app_sec_group]})
|
63
|
+
instance_b = CfFactory::CfEc2Instance.new("InstanceB",param_app_server_ami.generate_ref, "t1.micro", {:subnet => subnet_web_b, :vpc_security_groups => [app_sec_group]})
|
64
|
+
cf.add_resource(instance_a)
|
65
|
+
cf.add_resource(instance_b)
|
66
|
+
|
67
|
+
#elb
|
68
|
+
#health_check_string = "HTTP:#{param_app_port.generate_ref()}/index.html"
|
69
|
+
health_check_string = "HTTP:80/index.html"
|
70
|
+
elb = CfFactory::CfElb.new("MyLoadBalancer", {
|
71
|
+
:subnets => [subnet_elb_a, subnet_elb_b],
|
72
|
+
#:app_cookie_stickiness_policy => [CfAppCookieStickinessPolicy.new("cookiename","policybla")],
|
73
|
+
:health_check => CfFactory::CfHealthCheck.new("3","60", health_check_string,"10","2"),
|
74
|
+
:listeners => [CfFactory::CfListener.new(param_app_port.generate_ref(),"http","80","http")],
|
75
|
+
:security_groups => [elb_sec_group],
|
76
|
+
:instances => [instance_a, instance_b]
|
77
|
+
}
|
78
|
+
)
|
79
|
+
cf.add_resource(elb)
|
80
|
+
|
81
|
+
#cloudfront
|
82
|
+
origin = CfFactory::CfCustomOriginConfig.new("http-only",:http_port => 80)
|
83
|
+
origin_config = CfFactory::CfOrigin.new(elb.retrieve_attribute("DNSName") ,"CF001", origin)
|
84
|
+
default_cache_behavior = CfFactory::CfDefaultCacheBehavior.new(origin_config.id,CfFactory::CfForwardedValues.new(true),"allow-all",{:min_ttl => 0})
|
85
|
+
distribution_details = CfFactory::CfDistributionConfig.new([origin_config],default_cache_behavior,true)
|
86
|
+
cloudfront_distribution = CfFactory::CfCloudfrontDistribution.new("MyDistribution",distribution_details)
|
87
|
+
cf.add_resource(cloudfront_distribution)
|
88
|
+
|
89
|
+
####### output parameters
|
90
|
+
elb_output = CfFactory::CfOutput.new("ElbEndpoint","Endpoint of the ELB",elb.retrieve_attribute("DNSName"))
|
91
|
+
cf.add_output(elb_output)
|
92
|
+
cloudfront_domain = CfFactory::CfOutput.new("CloudfrontDomain", "Endpoint of the CloudFront distribution", cloudfront_distribution.retrieve_attribute("DomainName"))
|
93
|
+
cf.add_output(cloudfront_domain)
|
94
|
+
|
95
|
+
cf_json = cf.generate
|
96
|
+
puts cf_json
|
97
|
+
|
98
|
+
config_options = YAML.load_file("aws_config.yml")
|
99
|
+
validator = CfFactory::TemplateValidation.new(cf_json, config_options)
|
100
|
+
validator.validate()
|
@@ -1,40 +1,40 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
|
3
|
-
require 'cf_factory'
|
4
|
-
|
5
|
-
cf = CfFactory::CfMain.new("Playground")
|
6
|
-
##########################
|
7
|
-
|
8
|
-
mapping = CfFactory::CfMapping.new("Region2AmiMapping","AMI", {
|
9
|
-
"us-east-1" => "ami-c6699baf",
|
10
|
-
"us-west-2" => "ami-52ff7262",
|
11
|
-
"us-west-1" => "ami-3bcc9e7e",
|
12
|
-
"eu-west-1" => "ami-0b5b6c7f",
|
13
|
-
"ap-southeast-1" => "ami-02eb9350",
|
14
|
-
"ap-northeast-1" => "ami-14d86d15",
|
15
|
-
"sa-east-1" => "ami-0439e619"
|
16
|
-
})
|
17
|
-
cf.add_mapping(mapping)
|
18
|
-
ami = mapping.map_from_region()
|
19
|
-
instance = CfFactory::CfEc2Instance.new("MyInstance", ami, "t1.micro")
|
20
|
-
cf.add_resource(instance)
|
21
|
-
eip = CfFactory::CfEip.new("MyEip",instance)
|
22
|
-
cf.add_resource(eip)
|
23
|
-
instance_ip_assoc = CfFactory::CfEipAssociation.new("MyEipAllocation", eip, instance, nil)
|
24
|
-
cf.add_resource(instance_ip_assoc)
|
25
|
-
|
26
|
-
eip_output = CfFactory::CfOutput.new("Eip", "Id of the EIP", eip.generate_ref())
|
27
|
-
cf.add_output(eip_output)
|
28
|
-
#eip_ip_output = CfOutput.new("Eip", "Id of the EIP", eip.retrieve_attribute("AllocationId")) only works for VPC
|
29
|
-
#cf.add_output(eip_ip_output)
|
30
|
-
assoc_output = CfFactory::CfOutput.new("Assoc", "Id of the Assoc", instance_ip_assoc.generate_ref())
|
31
|
-
cf.add_output(assoc_output)
|
32
|
-
##########################
|
33
|
-
cf_json = cf.generate
|
34
|
-
puts cf_json
|
35
|
-
|
36
|
-
config_options = YAML.load_file("aws_config.yml")
|
37
|
-
#validator = CfFactory::TemplateValidation.new(cf_json, config_options)
|
38
|
-
#validator.validate()
|
39
|
-
#validator.apply()
|
40
|
-
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'cf_factory'
|
4
|
+
|
5
|
+
cf = CfFactory::CfMain.new("Playground")
|
6
|
+
##########################
|
7
|
+
|
8
|
+
mapping = CfFactory::CfMapping.new("Region2AmiMapping","AMI", {
|
9
|
+
"us-east-1" => "ami-c6699baf",
|
10
|
+
"us-west-2" => "ami-52ff7262",
|
11
|
+
"us-west-1" => "ami-3bcc9e7e",
|
12
|
+
"eu-west-1" => "ami-0b5b6c7f",
|
13
|
+
"ap-southeast-1" => "ami-02eb9350",
|
14
|
+
"ap-northeast-1" => "ami-14d86d15",
|
15
|
+
"sa-east-1" => "ami-0439e619"
|
16
|
+
})
|
17
|
+
cf.add_mapping(mapping)
|
18
|
+
ami = mapping.map_from_region()
|
19
|
+
instance = CfFactory::CfEc2Instance.new("MyInstance", ami, "t1.micro")
|
20
|
+
cf.add_resource(instance)
|
21
|
+
eip = CfFactory::CfEip.new("MyEip",instance)
|
22
|
+
cf.add_resource(eip)
|
23
|
+
instance_ip_assoc = CfFactory::CfEipAssociation.new("MyEipAllocation", eip, instance, nil)
|
24
|
+
cf.add_resource(instance_ip_assoc)
|
25
|
+
|
26
|
+
eip_output = CfFactory::CfOutput.new("Eip", "Id of the EIP", eip.generate_ref())
|
27
|
+
cf.add_output(eip_output)
|
28
|
+
#eip_ip_output = CfOutput.new("Eip", "Id of the EIP", eip.retrieve_attribute("AllocationId")) only works for VPC
|
29
|
+
#cf.add_output(eip_ip_output)
|
30
|
+
assoc_output = CfFactory::CfOutput.new("Assoc", "Id of the Assoc", instance_ip_assoc.generate_ref())
|
31
|
+
cf.add_output(assoc_output)
|
32
|
+
##########################
|
33
|
+
cf_json = cf.generate
|
34
|
+
puts cf_json
|
35
|
+
|
36
|
+
config_options = YAML.load_file("aws_config.yml")
|
37
|
+
#validator = CfFactory::TemplateValidation.new(cf_json, config_options)
|
38
|
+
#validator.validate()
|
39
|
+
#validator.apply()
|
40
|
+
|
@@ -1,40 +1,40 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
|
3
|
-
require 'cf_factory'
|
4
|
-
|
5
|
-
cf = CfFactory::CfMain.new("Playground")
|
6
|
-
##########################
|
7
|
-
|
8
|
-
mapping = CfFactory::CfMapping.new("Region2AmiMapping","AMI", {
|
9
|
-
"us-east-1" => "ami-c6699baf",
|
10
|
-
"us-west-2" => "ami-52ff7262",
|
11
|
-
"us-west-1" => "ami-3bcc9e7e",
|
12
|
-
"eu-west-1" => "ami-c37474b7",#"ami-0b5b6c7f",
|
13
|
-
"ap-southeast-1" => "ami-02eb9350",
|
14
|
-
"ap-northeast-1" => "ami-14d86d15",
|
15
|
-
"sa-east-1" => "ami-0439e619"
|
16
|
-
})
|
17
|
-
cf.add_mapping(mapping)
|
18
|
-
ami = mapping.map_from_region()
|
19
|
-
puts "AMI = #{ami}"
|
20
|
-
instance = CfFactory::CfEc2Instance.new("MyInstance", ami, "t1.micro", {:keyname => "majung-eu"})
|
21
|
-
cf.add_resource(instance)
|
22
|
-
|
23
|
-
packages = CfFactory::CfCloudFormationPackages.new([
|
24
|
-
CfFactory::CfCloudFormationPackage.new("yum", "rubygems", []),
|
25
|
-
CfFactory::CfCloudFormationPackage.new("yum", "rubygem-aws-sdk", []),
|
26
|
-
CfFactory::CfCloudFormationPackage.new("rubygems", "cloudyscripts", ["2.14.60"])
|
27
|
-
])
|
28
|
-
config = CfFactory::CfCloudFormationConfig.new("GemInstallation", nil, nil, nil, packages)
|
29
|
-
cloud_init_config = CfFactory::CfCloudFormationInit.new([config])
|
30
|
-
instance.set_meta_data(cloud_init_config)
|
31
|
-
|
32
|
-
##########################
|
33
|
-
cf_json = cf.generate
|
34
|
-
puts cf_json
|
35
|
-
|
36
|
-
config_options = YAML.load_file("aws_config.yml")
|
37
|
-
validator = CfFactory::TemplateValidation.new(cf_json, config_options)
|
38
|
-
validator.validate()
|
39
|
-
#validator.apply()
|
40
|
-
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'cf_factory'
|
4
|
+
|
5
|
+
cf = CfFactory::CfMain.new("Playground")
|
6
|
+
##########################
|
7
|
+
|
8
|
+
mapping = CfFactory::CfMapping.new("Region2AmiMapping","AMI", {
|
9
|
+
"us-east-1" => "ami-c6699baf",
|
10
|
+
"us-west-2" => "ami-52ff7262",
|
11
|
+
"us-west-1" => "ami-3bcc9e7e",
|
12
|
+
"eu-west-1" => "ami-c37474b7",#"ami-0b5b6c7f",
|
13
|
+
"ap-southeast-1" => "ami-02eb9350",
|
14
|
+
"ap-northeast-1" => "ami-14d86d15",
|
15
|
+
"sa-east-1" => "ami-0439e619"
|
16
|
+
})
|
17
|
+
cf.add_mapping(mapping)
|
18
|
+
ami = mapping.map_from_region()
|
19
|
+
puts "AMI = #{ami}"
|
20
|
+
instance = CfFactory::CfEc2Instance.new("MyInstance", ami, "t1.micro", {:keyname => "majung-eu"})
|
21
|
+
cf.add_resource(instance)
|
22
|
+
|
23
|
+
packages = CfFactory::CfCloudFormationPackages.new([
|
24
|
+
CfFactory::CfCloudFormationPackage.new("yum", "rubygems", []),
|
25
|
+
CfFactory::CfCloudFormationPackage.new("yum", "rubygem-aws-sdk", []),
|
26
|
+
CfFactory::CfCloudFormationPackage.new("rubygems", "cloudyscripts", ["2.14.60"])
|
27
|
+
])
|
28
|
+
config = CfFactory::CfCloudFormationConfig.new("GemInstallation", nil, nil, nil, packages)
|
29
|
+
cloud_init_config = CfFactory::CfCloudFormationInit.new([config])
|
30
|
+
instance.set_meta_data(cloud_init_config)
|
31
|
+
|
32
|
+
##########################
|
33
|
+
cf_json = cf.generate
|
34
|
+
puts cf_json
|
35
|
+
|
36
|
+
config_options = YAML.load_file("aws_config.yml")
|
37
|
+
validator = CfFactory::TemplateValidation.new(cf_json, config_options)
|
38
|
+
validator.validate()
|
39
|
+
#validator.apply()
|
40
|
+
|
@@ -1,31 +1,31 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
|
3
|
-
require 'cf_factory'
|
4
|
-
|
5
|
-
cf = CfFactory::CfMain.new("JustAnInstance")
|
6
|
-
##########################
|
7
|
-
|
8
|
-
mapping = CfFactory::CfMapping.new("Region2AmiMapping","AMI", {
|
9
|
-
"us-east-1" => "ami-c6699baf",
|
10
|
-
"us-west-2" => "ami-52ff7262",
|
11
|
-
"us-west-1" => "ami-3bcc9e7e",
|
12
|
-
"eu-west-1" => "ami-0b5b6c7f",
|
13
|
-
"ap-southeast-1" => "ami-02eb9350",
|
14
|
-
"ap-northeast-1" => "ami-14d86d15",
|
15
|
-
"sa-east-1" => "ami-0439e619"
|
16
|
-
})
|
17
|
-
cf.add_mapping(mapping)
|
18
|
-
ami = mapping.map_from_region()
|
19
|
-
puts "AMI = #{ami}"
|
20
|
-
instance = CfFactory::CfEc2Instance.new("MyInstance", ami, "t1.micro")
|
21
|
-
cf.add_resource(instance)
|
22
|
-
|
23
|
-
##########################
|
24
|
-
cf_json = cf.generate
|
25
|
-
puts cf_json
|
26
|
-
|
27
|
-
config_options = YAML.load_file("aws_config.yml")
|
28
|
-
validator = CfFactory::TemplateValidation.new(cf_json, config_options)
|
29
|
-
validator.validate()
|
30
|
-
|
31
|
-
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'cf_factory'
|
4
|
+
|
5
|
+
cf = CfFactory::CfMain.new("JustAnInstance")
|
6
|
+
##########################
|
7
|
+
|
8
|
+
mapping = CfFactory::CfMapping.new("Region2AmiMapping","AMI", {
|
9
|
+
"us-east-1" => "ami-c6699baf",
|
10
|
+
"us-west-2" => "ami-52ff7262",
|
11
|
+
"us-west-1" => "ami-3bcc9e7e",
|
12
|
+
"eu-west-1" => "ami-0b5b6c7f",
|
13
|
+
"ap-southeast-1" => "ami-02eb9350",
|
14
|
+
"ap-northeast-1" => "ami-14d86d15",
|
15
|
+
"sa-east-1" => "ami-0439e619"
|
16
|
+
})
|
17
|
+
cf.add_mapping(mapping)
|
18
|
+
ami = mapping.map_from_region()
|
19
|
+
puts "AMI = #{ami}"
|
20
|
+
instance = CfFactory::CfEc2Instance.new("MyInstance", ami, "t1.micro")
|
21
|
+
cf.add_resource(instance)
|
22
|
+
|
23
|
+
##########################
|
24
|
+
cf_json = cf.generate
|
25
|
+
puts cf_json
|
26
|
+
|
27
|
+
config_options = YAML.load_file("aws_config.yml")
|
28
|
+
validator = CfFactory::TemplateValidation.new(cf_json, config_options)
|
29
|
+
validator.validate()
|
30
|
+
|
31
|
+
|
@@ -1,69 +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
|
+
#!/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,28 +1,28 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
|
3
|
-
require 'cf_factory'
|
4
|
-
|
5
|
-
cf = CfFactory::CfMain.new("Playground")
|
6
|
-
##########################
|
7
|
-
ami = "ami-6d555119"
|
8
|
-
|
9
|
-
az = CfFactory::CfHelper.az_in_region("a")
|
10
|
-
instance = CfFactory::CfEc2Instance.new("MyInstance", ami, "t1.micro", {:availability_zone => az })
|
11
|
-
cf.add_resource(instance)
|
12
|
-
|
13
|
-
region_output = CfFactory::CfOutput.new("Region", "Region the stack was started", CfFactory::CfHelper.ref_current_region())
|
14
|
-
cf.add_output(region_output)
|
15
|
-
target_zone_output = CfFactory::CfOutput.new("TargetZone", "AZ where instance to be started", az)
|
16
|
-
cf.add_output(target_zone_output)
|
17
|
-
actual_zone_output = CfFactory::CfOutput.new("ActualInstanceZone", "AZ of started instance", instance.retrieve_attribute("AvailabilityZone"))
|
18
|
-
cf.add_output(actual_zone_output)
|
19
|
-
|
20
|
-
##########################
|
21
|
-
cf_json = cf.generate
|
22
|
-
puts cf_json
|
23
|
-
|
24
|
-
config_options = YAML.load_file("aws_config.yml")
|
25
|
-
validator = CfFactory::TemplateValidation.new(cf_json, config_options)
|
26
|
-
validator.validate()
|
27
|
-
|
28
|
-
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'cf_factory'
|
4
|
+
|
5
|
+
cf = CfFactory::CfMain.new("Playground")
|
6
|
+
##########################
|
7
|
+
ami = "ami-6d555119"
|
8
|
+
|
9
|
+
az = CfFactory::CfHelper.az_in_region("a")
|
10
|
+
instance = CfFactory::CfEc2Instance.new("MyInstance", ami, "t1.micro", {:availability_zone => az })
|
11
|
+
cf.add_resource(instance)
|
12
|
+
|
13
|
+
region_output = CfFactory::CfOutput.new("Region", "Region the stack was started", CfFactory::CfHelper.ref_current_region())
|
14
|
+
cf.add_output(region_output)
|
15
|
+
target_zone_output = CfFactory::CfOutput.new("TargetZone", "AZ where instance to be started", az)
|
16
|
+
cf.add_output(target_zone_output)
|
17
|
+
actual_zone_output = CfFactory::CfOutput.new("ActualInstanceZone", "AZ of started instance", instance.retrieve_attribute("AvailabilityZone"))
|
18
|
+
cf.add_output(actual_zone_output)
|
19
|
+
|
20
|
+
##########################
|
21
|
+
cf_json = cf.generate
|
22
|
+
puts cf_json
|
23
|
+
|
24
|
+
config_options = YAML.load_file("aws_config.yml")
|
25
|
+
validator = CfFactory::TemplateValidation.new(cf_json, config_options)
|
26
|
+
validator.validate()
|
27
|
+
|
28
|
+
|