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/bin/cf_factory
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
|
3
|
-
require 'cf_factory'
|
4
|
-
|
5
|
-
puts "cf_factory command line tool placeholder"
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'cf_factory'
|
4
|
+
|
5
|
+
puts "cf_factory command line tool placeholder"
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
|
data/examples/base_vpc.rb
CHANGED
@@ -1,40 +1,40 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
|
3
|
-
require 'cf_factory'
|
4
|
-
|
5
|
-
cf = CfFactory::CfMain.new("Bla bla bla")
|
6
|
-
####### input parameters
|
7
|
-
parameter = CfFactory::CfParameter.new("KeyName", "Name of the key", "String", {"Default" => "majung"})
|
8
|
-
cf.add_parameter(parameter)
|
9
|
-
parameter2 = CfFactory::CfParameter.new("SecurityGroup", "Name of the security group", "String", {"Default" => "Blubber"})
|
10
|
-
cf.add_parameter(parameter2)
|
11
|
-
|
12
|
-
####### mappings
|
13
|
-
mapping = CfFactory::CfMapping.new("Default","AMI",{"us-east-1" => "ami-c6699baf", "us-west-2" => "ami-52ff7262"})
|
14
|
-
cf.add_mapping(mapping)
|
15
|
-
|
16
|
-
####### resources
|
17
|
-
#vpc
|
18
|
-
base_vpc = CfFactory::BaseVpc.new("BaseVpc","192.168.0.0/16",2,4,["eu-west-1a","eu-west-1b"],256)
|
19
|
-
base_vpc.add_to_template(cf)
|
20
|
-
vpc = base_vpc.vpc
|
21
|
-
|
22
|
-
network_acl = CfFactory::CfNetworkAcl.new("MyAcl1")
|
23
|
-
vpc.add_network_acl(network_acl)
|
24
|
-
network_acl_entry = CfFactory::CfNetworkAclEntry.new("Acl1", "110", "6", "ALLOW", false, "0.0.0.0/0", 80, 80)
|
25
|
-
network_acl.add_network_acl_entry(network_acl_entry)
|
26
|
-
|
27
|
-
####### output parameters
|
28
|
-
output = CfFactory::CfOutput.new("BaseVpc", "Id of the VPC", vpc.generate_ref())
|
29
|
-
cf.add_output(output)
|
30
|
-
|
31
|
-
cf_json = cf.generate
|
32
|
-
puts cf_json
|
33
|
-
|
34
|
-
config_options = YAML.load_file("aws_config.yml")
|
35
|
-
config_options["cloud_formation_endpoint"] = "cloudformation.us-east-1.amazonaws.com"
|
36
|
-
puts config_options.inspect
|
37
|
-
validator = CfFactory::TemplateValidation.new(cf_json, config_options)
|
38
|
-
validator.validate()
|
39
|
-
|
40
|
-
#puts "the reference for the VPC : #{vpc.generate_ref}"
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'cf_factory'
|
4
|
+
|
5
|
+
cf = CfFactory::CfMain.new("Bla bla bla")
|
6
|
+
####### input parameters
|
7
|
+
parameter = CfFactory::CfParameter.new("KeyName", "Name of the key", "String", {"Default" => "majung"})
|
8
|
+
cf.add_parameter(parameter)
|
9
|
+
parameter2 = CfFactory::CfParameter.new("SecurityGroup", "Name of the security group", "String", {"Default" => "Blubber"})
|
10
|
+
cf.add_parameter(parameter2)
|
11
|
+
|
12
|
+
####### mappings
|
13
|
+
mapping = CfFactory::CfMapping.new("Default","AMI",{"us-east-1" => "ami-c6699baf", "us-west-2" => "ami-52ff7262"})
|
14
|
+
cf.add_mapping(mapping)
|
15
|
+
|
16
|
+
####### resources
|
17
|
+
#vpc
|
18
|
+
base_vpc = CfFactory::BaseVpc.new("BaseVpc","192.168.0.0/16",2,4,["eu-west-1a","eu-west-1b"],256)
|
19
|
+
base_vpc.add_to_template(cf)
|
20
|
+
vpc = base_vpc.vpc
|
21
|
+
|
22
|
+
network_acl = CfFactory::CfNetworkAcl.new("MyAcl1")
|
23
|
+
vpc.add_network_acl(network_acl)
|
24
|
+
network_acl_entry = CfFactory::CfNetworkAclEntry.new("Acl1", "110", "6", "ALLOW", false, "0.0.0.0/0", 80, 80)
|
25
|
+
network_acl.add_network_acl_entry(network_acl_entry)
|
26
|
+
|
27
|
+
####### output parameters
|
28
|
+
output = CfFactory::CfOutput.new("BaseVpc", "Id of the VPC", vpc.generate_ref())
|
29
|
+
cf.add_output(output)
|
30
|
+
|
31
|
+
cf_json = cf.generate
|
32
|
+
puts cf_json
|
33
|
+
|
34
|
+
config_options = YAML.load_file("aws_config.yml")
|
35
|
+
config_options["cloud_formation_endpoint"] = "cloudformation.us-east-1.amazonaws.com"
|
36
|
+
puts config_options.inspect
|
37
|
+
validator = CfFactory::TemplateValidation.new(cf_json, config_options)
|
38
|
+
validator.validate()
|
39
|
+
|
40
|
+
#puts "the reference for the VPC : #{vpc.generate_ref}"
|
@@ -1,23 +1,23 @@
|
|
1
|
-
require 'help/include_libraries'
|
2
|
-
|
3
|
-
#INCOMPLETE: seems as if the OriginAccessIdentity cannot be created via CloudFormation
|
4
|
-
|
5
|
-
# CloudFormation template that creates an S3 bucket that allows private access
|
6
|
-
# to a cloudfront distribution.
|
7
|
-
# What remains at the end:
|
8
|
-
# - create content in S3 bucket
|
9
|
-
# - create cloudfront access keys (Account -> Security Credentials)
|
10
|
-
# - use a library to sign that content
|
11
|
-
cf = CfMain.new("CloudFront for private content")
|
12
|
-
s3_bucket = CfS3.new("majung-cloudfront-private-1")
|
13
|
-
cf.add_resource(s3_bucket)
|
14
|
-
|
15
|
-
#cloudfront
|
16
|
-
origin = CfCustomOriginConfig.new("http-only",:http_port => 80)
|
17
|
-
origin_config = CfOrigin.new(elb.retrieve_attribute("DNSName") ,"CF001", origin)
|
18
|
-
origin_config = CfS3OriginConfig.new(options)
|
19
|
-
default_cache_behavior = CfDefaultCacheBehavior.new(origin_config.id,CfForwardedValues.new(true),"allow-all",{:min_ttl => 0})
|
20
|
-
distribution_details = CfDistributionConfig.new([origin_config],default_cache_behavior,true)
|
21
|
-
cloudfront_distribution = CfCloudfrontDistribution.new("MyDistribution",distribution_details)
|
22
|
-
cf.add_resource(cloudfront_distribution)
|
23
|
-
|
1
|
+
require 'help/include_libraries'
|
2
|
+
|
3
|
+
#INCOMPLETE: seems as if the OriginAccessIdentity cannot be created via CloudFormation
|
4
|
+
|
5
|
+
# CloudFormation template that creates an S3 bucket that allows private access
|
6
|
+
# to a cloudfront distribution.
|
7
|
+
# What remains at the end:
|
8
|
+
# - create content in S3 bucket
|
9
|
+
# - create cloudfront access keys (Account -> Security Credentials)
|
10
|
+
# - use a library to sign that content
|
11
|
+
cf = CfMain.new("CloudFront for private content")
|
12
|
+
s3_bucket = CfS3.new("majung-cloudfront-private-1")
|
13
|
+
cf.add_resource(s3_bucket)
|
14
|
+
|
15
|
+
#cloudfront
|
16
|
+
origin = CfCustomOriginConfig.new("http-only",:http_port => 80)
|
17
|
+
origin_config = CfOrigin.new(elb.retrieve_attribute("DNSName") ,"CF001", origin)
|
18
|
+
origin_config = CfS3OriginConfig.new(options)
|
19
|
+
default_cache_behavior = CfDefaultCacheBehavior.new(origin_config.id,CfForwardedValues.new(true),"allow-all",{:min_ttl => 0})
|
20
|
+
distribution_details = CfDistributionConfig.new([origin_config],default_cache_behavior,true)
|
21
|
+
cloudfront_distribution = CfCloudfrontDistribution.new("MyDistribution",distribution_details)
|
22
|
+
cf.add_resource(cloudfront_distribution)
|
23
|
+
|
@@ -1,77 +1,77 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
|
3
|
-
require 'cf_factory'
|
4
|
-
|
5
|
-
cf = CfFactory::CfMain.new("Playground")
|
6
|
-
##########################
|
7
|
-
ami = "ami-1624987f"
|
8
|
-
|
9
|
-
input_keyname = CfFactory::CfParameter.new("KeyName","Name of key for SSH access","String",{"Default" => "majung"})
|
10
|
-
cf.add_parameter(input_keyname)
|
11
|
-
input_ami = CfFactory::CfParameter.new("AMI","ID of AMI for instance","String",{"Default" => ami})
|
12
|
-
cf.add_parameter(input_ami)
|
13
|
-
|
14
|
-
statement = CfFactory::CfIamStatement.new("Allow","cloudformation:DescribeStackResource","*")
|
15
|
-
role_policy = CfFactory::CfIamPolicy.new("MyRolePolicy", CfFactory::CfPolicyDocument.new([statement]))
|
16
|
-
iam_user = CfFactory::CfIamUser.new("IamUser","/",{:policies => [role_policy]})
|
17
|
-
cf.add_resource(iam_user)
|
18
|
-
iam_access_key = CfFactory::CfIamAccessKey.new("IamAccessKey",iam_user.generate_ref,"Active")
|
19
|
-
cf.add_resource(iam_access_key)
|
20
|
-
|
21
|
-
script = CfFactory::CfInitScript.create_basic("MyInstance",iam_access_key.generate_ref,iam_access_key.retrieve_attribute("SecretAccessKey"))
|
22
|
-
#full_init_script = script.user_data()
|
23
|
-
|
24
|
-
full_init_script = CfFactory::CfHelper.join([
|
25
|
-
"#!/bin/bash -v\\n",
|
26
|
-
"yum update -y aws-cfn-bootstrap\\n",
|
27
|
-
"/opt/aws/bin/cfn-init -s ", CfFactory::CfHelper.generate_ref("AWS::StackName"),
|
28
|
-
" -r ", "MyInstance ",
|
29
|
-
" --access-key ", iam_access_key.generate_ref,
|
30
|
-
" --secret-key ", iam_access_key.retrieve_attribute("SecretAccessKey")]
|
31
|
-
)
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
instance = CfFactory::CfEc2Instance.new("MyInstance",input_ami.generate_ref,"m1.small",
|
36
|
-
{:keyname => input_keyname.generate_ref(),
|
37
|
-
:user_data => full_init_script
|
38
|
-
}
|
39
|
-
)
|
40
|
-
packages = CfFactory::CfCloudFormationPackages.new([CfFactory::CfCloudFormationPackage.new("yum","httpd","2.2.13")])
|
41
|
-
commands = CfFactory::CfCloudFormationCommands.new([
|
42
|
-
CfFactory::CfCloudFormationCommand.new("command1","echo cloudinit"),
|
43
|
-
CfFactory::CfCloudFormationCommand.new("command2","echo cloudinit > /var/log/my-cloudinit.txt")
|
44
|
-
])
|
45
|
-
config1 = CfFactory::CfCloudFormationConfig.new("config1", nil, commands, nil, packages)
|
46
|
-
config2 = CfFactory::CfCloudFormationConfig.new("config", nil, commands, nil, nil)
|
47
|
-
|
48
|
-
meta_data = CfFactory::CfCloudFormationInit.new([config2])
|
49
|
-
instance.set_meta_data(meta_data)
|
50
|
-
cf.add_resource(instance)
|
51
|
-
|
52
|
-
stackname = CfFactory::CfOutput.new("StackName","Name of CloudFormation stack",CfFactory::CfHelper.generate_ref("AWS::StackName"))
|
53
|
-
cf.add_output(stackname)
|
54
|
-
instance_ip = CfFactory::CfOutput.new("InstanceIp","DNS Name of instance created",instance.retrieve_attribute("PublicDnsName"))
|
55
|
-
cf.add_output(instance_ip)
|
56
|
-
access_key = CfFactory::CfOutput.new("AccessKey","Access key",iam_access_key.generate_ref)
|
57
|
-
cf.add_output(access_key)
|
58
|
-
secret_key = CfFactory::CfOutput.new("SecretKey","Secret key",iam_access_key.retrieve_attribute("SecretAccessKey"))
|
59
|
-
cf.add_output(secret_key)
|
60
|
-
|
61
|
-
output_command = CfFactory::CfOutput.new("FullCommand", "Full command to be executed",
|
62
|
-
CfFactory::CfHelper.join(["/opt/aws/bin/cfn-init -s ", CfFactory::CfHelper.generate_ref("AWS::StackName"),
|
63
|
-
" -r ", instance.get_name(),
|
64
|
-
" --access-key ", iam_access_key.generate_ref,
|
65
|
-
" --secret-key ", iam_access_key.retrieve_attribute("SecretAccessKey")]
|
66
|
-
))
|
67
|
-
cf.add_output(output_command)
|
68
|
-
|
69
|
-
##########################
|
70
|
-
cf_json = cf.generate
|
71
|
-
puts cf_json
|
72
|
-
|
73
|
-
config_options = YAML.load_file("aws_config.yml")
|
74
|
-
config_options["cloud_formation_endpoint"] = "cloudformation.us-east-1.amazonaws.com"
|
75
|
-
validator = CfFactory::TemplateValidation.new(cf_json, config_options)
|
76
|
-
validator.validate()
|
77
|
-
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'cf_factory'
|
4
|
+
|
5
|
+
cf = CfFactory::CfMain.new("Playground")
|
6
|
+
##########################
|
7
|
+
ami = "ami-1624987f"
|
8
|
+
|
9
|
+
input_keyname = CfFactory::CfParameter.new("KeyName","Name of key for SSH access","String",{"Default" => "majung"})
|
10
|
+
cf.add_parameter(input_keyname)
|
11
|
+
input_ami = CfFactory::CfParameter.new("AMI","ID of AMI for instance","String",{"Default" => ami})
|
12
|
+
cf.add_parameter(input_ami)
|
13
|
+
|
14
|
+
statement = CfFactory::CfIamStatement.new("Allow","cloudformation:DescribeStackResource","*")
|
15
|
+
role_policy = CfFactory::CfIamPolicy.new("MyRolePolicy", CfFactory::CfPolicyDocument.new([statement]))
|
16
|
+
iam_user = CfFactory::CfIamUser.new("IamUser","/",{:policies => [role_policy]})
|
17
|
+
cf.add_resource(iam_user)
|
18
|
+
iam_access_key = CfFactory::CfIamAccessKey.new("IamAccessKey",iam_user.generate_ref,"Active")
|
19
|
+
cf.add_resource(iam_access_key)
|
20
|
+
|
21
|
+
script = CfFactory::CfInitScript.create_basic("MyInstance",iam_access_key.generate_ref,iam_access_key.retrieve_attribute("SecretAccessKey"))
|
22
|
+
#full_init_script = script.user_data()
|
23
|
+
|
24
|
+
full_init_script = CfFactory::CfHelper.join([
|
25
|
+
"#!/bin/bash -v\\n",
|
26
|
+
"yum update -y aws-cfn-bootstrap\\n",
|
27
|
+
"/opt/aws/bin/cfn-init -s ", CfFactory::CfHelper.generate_ref("AWS::StackName"),
|
28
|
+
" -r ", "MyInstance ",
|
29
|
+
" --access-key ", iam_access_key.generate_ref,
|
30
|
+
" --secret-key ", iam_access_key.retrieve_attribute("SecretAccessKey")]
|
31
|
+
)
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
instance = CfFactory::CfEc2Instance.new("MyInstance",input_ami.generate_ref,"m1.small",
|
36
|
+
{:keyname => input_keyname.generate_ref(),
|
37
|
+
:user_data => full_init_script
|
38
|
+
}
|
39
|
+
)
|
40
|
+
packages = CfFactory::CfCloudFormationPackages.new([CfFactory::CfCloudFormationPackage.new("yum","httpd","2.2.13")])
|
41
|
+
commands = CfFactory::CfCloudFormationCommands.new([
|
42
|
+
CfFactory::CfCloudFormationCommand.new("command1","echo cloudinit"),
|
43
|
+
CfFactory::CfCloudFormationCommand.new("command2","echo cloudinit > /var/log/my-cloudinit.txt")
|
44
|
+
])
|
45
|
+
config1 = CfFactory::CfCloudFormationConfig.new("config1", nil, commands, nil, packages)
|
46
|
+
config2 = CfFactory::CfCloudFormationConfig.new("config", nil, commands, nil, nil)
|
47
|
+
|
48
|
+
meta_data = CfFactory::CfCloudFormationInit.new([config2])
|
49
|
+
instance.set_meta_data(meta_data)
|
50
|
+
cf.add_resource(instance)
|
51
|
+
|
52
|
+
stackname = CfFactory::CfOutput.new("StackName","Name of CloudFormation stack",CfFactory::CfHelper.generate_ref("AWS::StackName"))
|
53
|
+
cf.add_output(stackname)
|
54
|
+
instance_ip = CfFactory::CfOutput.new("InstanceIp","DNS Name of instance created",instance.retrieve_attribute("PublicDnsName"))
|
55
|
+
cf.add_output(instance_ip)
|
56
|
+
access_key = CfFactory::CfOutput.new("AccessKey","Access key",iam_access_key.generate_ref)
|
57
|
+
cf.add_output(access_key)
|
58
|
+
secret_key = CfFactory::CfOutput.new("SecretKey","Secret key",iam_access_key.retrieve_attribute("SecretAccessKey"))
|
59
|
+
cf.add_output(secret_key)
|
60
|
+
|
61
|
+
output_command = CfFactory::CfOutput.new("FullCommand", "Full command to be executed",
|
62
|
+
CfFactory::CfHelper.join(["/opt/aws/bin/cfn-init -s ", CfFactory::CfHelper.generate_ref("AWS::StackName"),
|
63
|
+
" -r ", instance.get_name(),
|
64
|
+
" --access-key ", iam_access_key.generate_ref,
|
65
|
+
" --secret-key ", iam_access_key.retrieve_attribute("SecretAccessKey")]
|
66
|
+
))
|
67
|
+
cf.add_output(output_command)
|
68
|
+
|
69
|
+
##########################
|
70
|
+
cf_json = cf.generate
|
71
|
+
puts cf_json
|
72
|
+
|
73
|
+
config_options = YAML.load_file("aws_config.yml")
|
74
|
+
config_options["cloud_formation_endpoint"] = "cloudformation.us-east-1.amazonaws.com"
|
75
|
+
validator = CfFactory::TemplateValidation.new(cf_json, config_options)
|
76
|
+
validator.validate()
|
77
|
+
|
@@ -1,85 +1,85 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
|
3
|
-
require 'cf_factory'
|
4
|
-
|
5
|
-
cf = CfFactory::CfMain.new("Playground")
|
6
|
-
##########################
|
7
|
-
ami = "ami-1624987f"
|
8
|
-
|
9
|
-
input_keyname = CfFactory::CfParameter.new("KeyName","Name of key for SSH access","String",{"Default" => "majung"})
|
10
|
-
cf.add_parameter(input_keyname)
|
11
|
-
input_ami = CfFactory::CfParameter.new("AMI","ID of AMI for instance","String",{"Default" => ami})
|
12
|
-
cf.add_parameter(input_ami)
|
13
|
-
|
14
|
-
statement = CfFactory::CfIamStatement.new("Allow","cloudformation:DescribeStackResource","*")
|
15
|
-
role_policy = CfFactory::CfIamPolicy.new("MyRolePolicy", CfFactory::CfPolicyDocument.new([statement]))
|
16
|
-
iam_user = CfFactory::CfIamUser.new("IamUser","/",{:policies => [role_policy]})
|
17
|
-
cf.add_resource(iam_user)
|
18
|
-
iam_access_key = CfFactory::CfIamAccessKey.new("IamAccessKey",iam_user.generate_ref,"Active")
|
19
|
-
cf.add_resource(iam_access_key)
|
20
|
-
|
21
|
-
script = CfFactory::CfInitScript.create_basic("MyInstance",iam_access_key.generate_ref,iam_access_key.retrieve_attribute("SecretAccessKey"))
|
22
|
-
#full_init_script = script.user_data()
|
23
|
-
full_init_script = CfFactory::CfHelper.join([
|
24
|
-
"#!/bin/bash -v\\n",
|
25
|
-
"yum update -y aws-cfn-bootstrap\\n",
|
26
|
-
"/opt/aws/bin/cfn-init -s ", CfFactory::CfHelper.generate_ref("AWS::StackName"),
|
27
|
-
" -r ", "InstanceLaunchConfig ",
|
28
|
-
" --access-key ", iam_access_key.generate_ref,
|
29
|
-
" --secret-key ", iam_access_key.retrieve_attribute("SecretAccessKey")]
|
30
|
-
)
|
31
|
-
|
32
|
-
packages = CfFactory::CfCloudFormationPackages.new([CfFactory::CfCloudFormationPackage.new("yum","httpd","2.2.13")])
|
33
|
-
commands = CfFactory::CfCloudFormationCommands.new([
|
34
|
-
CfFactory::CfCloudFormationCommand.new("command1","echo cloudinit"),
|
35
|
-
CfFactory::CfCloudFormationCommand.new("command2","echo cloudinit > /var/log/my-cloudinit.txt")
|
36
|
-
])
|
37
|
-
config1 = CfFactory::CfCloudFormationConfig.new("config1", nil, commands, nil, packages)
|
38
|
-
config2 = CfFactory::CfCloudFormationConfig.new("config", nil, commands, nil, nil)
|
39
|
-
|
40
|
-
#auto-scaling group
|
41
|
-
launch_config = CfFactory::CfAsLaunchConfig.new("InstanceLaunchConfig", input_ami.generate_ref, "t1.micro", { :key_name => input_keyname.generate_ref(), :user_data => full_init_script})
|
42
|
-
meta_data = CfFactory::CfCloudFormationInit.new([config2])
|
43
|
-
launch_config.set_meta_data(meta_data)
|
44
|
-
cf.add_resource(launch_config)
|
45
|
-
availability_zones = CfFactory::CfHelper.az_array_in_region(["b","c"])
|
46
|
-
as_group = CfFactory::CfAsGroup.new("AppServerFleet",availability_zones, launch_config, [], 4 ,2 ,{:desired_capacity => 2})
|
47
|
-
cf.add_resource(as_group)
|
48
|
-
as_up_scaling_policy = CfFactory::CfAsScalingPolicy.new("MyUpscalePolicy",as_group,"ChangeInCapacity","1",{:cooldown => 300})
|
49
|
-
cf.add_resource(as_up_scaling_policy)
|
50
|
-
as_down_scaling_policy = CfFactory::CfAsScalingPolicy.new("MyDownscalePolicy",as_group,"ChangeInCapacity","-1",{:cooldown => 300})
|
51
|
-
cf.add_resource(as_down_scaling_policy)
|
52
|
-
as_up_alarm = CfFactory::CfCloudWatchAlarm.new("MyUpAlarm",CfFactory::CfCloudWatchAlarm::GREATER_THAN_OR_EQUAL_TO_THRESHOLD, "3", "CPUUtilization","AWS/EC2",
|
53
|
-
"60","Average","80", {:alarm_actions => [as_up_scaling_policy]})
|
54
|
-
as_down_alarm = CfFactory::CfCloudWatchAlarm.new("MyDownAlarm",CfFactory::CfCloudWatchAlarm::LESS_THAN_THRESHOLD, "3", "CPUUtilization","AWS/EC2",
|
55
|
-
"60","Average","30", {:alarm_actions => [as_down_scaling_policy]})
|
56
|
-
cf.add_resource(as_up_alarm)
|
57
|
-
cf.add_resource(as_down_alarm)
|
58
|
-
|
59
|
-
stackname = CfFactory::CfOutput.new("StackName","Name of CloudFormation stack",CfFactory::CfHelper.generate_ref("AWS::StackName"))
|
60
|
-
cf.add_output(stackname)
|
61
|
-
access_key = CfFactory::CfOutput.new("AccessKey","Access key",iam_access_key.generate_ref)
|
62
|
-
cf.add_output(access_key)
|
63
|
-
secret_key = CfFactory::CfOutput.new("SecretKey","Secret key",iam_access_key.retrieve_attribute("SecretAccessKey"))
|
64
|
-
cf.add_output(secret_key)
|
65
|
-
|
66
|
-
output_command = CfFactory::CfOutput.new("FullCommand", "Full command to be executed",
|
67
|
-
CfFactory::CfHelper.join(["/opt/aws/bin/cfn-init -s ", CfFactory::CfHelper.generate_ref("AWS::StackName"),
|
68
|
-
" -r ", launch_config.get_name(),
|
69
|
-
" --access-key ", iam_access_key.generate_ref,
|
70
|
-
" --secret-key ", iam_access_key.retrieve_attribute("SecretAccessKey")]
|
71
|
-
))
|
72
|
-
cf.add_output(output_command)
|
73
|
-
|
74
|
-
tag = CfFactory::CfEc2Tag.new("CloudFormationTests","active")
|
75
|
-
cf.apply_tags_to_all_resources([tag])
|
76
|
-
|
77
|
-
##########################
|
78
|
-
cf_json = cf.generate
|
79
|
-
puts cf_json
|
80
|
-
|
81
|
-
config_options = YAML.load_file("aws_config.yml")
|
82
|
-
config_options["cloud_formation_endpoint"] = "cloudformation.us-east-1.amazonaws.com"
|
83
|
-
validator = CfFactory::TemplateValidation.new(cf_json, config_options)
|
84
|
-
validator.validate()
|
85
|
-
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'cf_factory'
|
4
|
+
|
5
|
+
cf = CfFactory::CfMain.new("Playground")
|
6
|
+
##########################
|
7
|
+
ami = "ami-1624987f"
|
8
|
+
|
9
|
+
input_keyname = CfFactory::CfParameter.new("KeyName","Name of key for SSH access","String",{"Default" => "majung"})
|
10
|
+
cf.add_parameter(input_keyname)
|
11
|
+
input_ami = CfFactory::CfParameter.new("AMI","ID of AMI for instance","String",{"Default" => ami})
|
12
|
+
cf.add_parameter(input_ami)
|
13
|
+
|
14
|
+
statement = CfFactory::CfIamStatement.new("Allow","cloudformation:DescribeStackResource","*")
|
15
|
+
role_policy = CfFactory::CfIamPolicy.new("MyRolePolicy", CfFactory::CfPolicyDocument.new([statement]))
|
16
|
+
iam_user = CfFactory::CfIamUser.new("IamUser","/",{:policies => [role_policy]})
|
17
|
+
cf.add_resource(iam_user)
|
18
|
+
iam_access_key = CfFactory::CfIamAccessKey.new("IamAccessKey",iam_user.generate_ref,"Active")
|
19
|
+
cf.add_resource(iam_access_key)
|
20
|
+
|
21
|
+
script = CfFactory::CfInitScript.create_basic("MyInstance",iam_access_key.generate_ref,iam_access_key.retrieve_attribute("SecretAccessKey"))
|
22
|
+
#full_init_script = script.user_data()
|
23
|
+
full_init_script = CfFactory::CfHelper.join([
|
24
|
+
"#!/bin/bash -v\\n",
|
25
|
+
"yum update -y aws-cfn-bootstrap\\n",
|
26
|
+
"/opt/aws/bin/cfn-init -s ", CfFactory::CfHelper.generate_ref("AWS::StackName"),
|
27
|
+
" -r ", "InstanceLaunchConfig ",
|
28
|
+
" --access-key ", iam_access_key.generate_ref,
|
29
|
+
" --secret-key ", iam_access_key.retrieve_attribute("SecretAccessKey")]
|
30
|
+
)
|
31
|
+
|
32
|
+
packages = CfFactory::CfCloudFormationPackages.new([CfFactory::CfCloudFormationPackage.new("yum","httpd","2.2.13")])
|
33
|
+
commands = CfFactory::CfCloudFormationCommands.new([
|
34
|
+
CfFactory::CfCloudFormationCommand.new("command1","echo cloudinit"),
|
35
|
+
CfFactory::CfCloudFormationCommand.new("command2","echo cloudinit > /var/log/my-cloudinit.txt")
|
36
|
+
])
|
37
|
+
config1 = CfFactory::CfCloudFormationConfig.new("config1", nil, commands, nil, packages)
|
38
|
+
config2 = CfFactory::CfCloudFormationConfig.new("config", nil, commands, nil, nil)
|
39
|
+
|
40
|
+
#auto-scaling group
|
41
|
+
launch_config = CfFactory::CfAsLaunchConfig.new("InstanceLaunchConfig", input_ami.generate_ref, "t1.micro", { :key_name => input_keyname.generate_ref(), :user_data => full_init_script})
|
42
|
+
meta_data = CfFactory::CfCloudFormationInit.new([config2])
|
43
|
+
launch_config.set_meta_data(meta_data)
|
44
|
+
cf.add_resource(launch_config)
|
45
|
+
availability_zones = CfFactory::CfHelper.az_array_in_region(["b","c"])
|
46
|
+
as_group = CfFactory::CfAsGroup.new("AppServerFleet",availability_zones, launch_config, [], 4 ,2 ,{:desired_capacity => 2})
|
47
|
+
cf.add_resource(as_group)
|
48
|
+
as_up_scaling_policy = CfFactory::CfAsScalingPolicy.new("MyUpscalePolicy",as_group,"ChangeInCapacity","1",{:cooldown => 300})
|
49
|
+
cf.add_resource(as_up_scaling_policy)
|
50
|
+
as_down_scaling_policy = CfFactory::CfAsScalingPolicy.new("MyDownscalePolicy",as_group,"ChangeInCapacity","-1",{:cooldown => 300})
|
51
|
+
cf.add_resource(as_down_scaling_policy)
|
52
|
+
as_up_alarm = CfFactory::CfCloudWatchAlarm.new("MyUpAlarm",CfFactory::CfCloudWatchAlarm::GREATER_THAN_OR_EQUAL_TO_THRESHOLD, "3", "CPUUtilization","AWS/EC2",
|
53
|
+
"60","Average","80", {:alarm_actions => [as_up_scaling_policy]})
|
54
|
+
as_down_alarm = CfFactory::CfCloudWatchAlarm.new("MyDownAlarm",CfFactory::CfCloudWatchAlarm::LESS_THAN_THRESHOLD, "3", "CPUUtilization","AWS/EC2",
|
55
|
+
"60","Average","30", {:alarm_actions => [as_down_scaling_policy]})
|
56
|
+
cf.add_resource(as_up_alarm)
|
57
|
+
cf.add_resource(as_down_alarm)
|
58
|
+
|
59
|
+
stackname = CfFactory::CfOutput.new("StackName","Name of CloudFormation stack",CfFactory::CfHelper.generate_ref("AWS::StackName"))
|
60
|
+
cf.add_output(stackname)
|
61
|
+
access_key = CfFactory::CfOutput.new("AccessKey","Access key",iam_access_key.generate_ref)
|
62
|
+
cf.add_output(access_key)
|
63
|
+
secret_key = CfFactory::CfOutput.new("SecretKey","Secret key",iam_access_key.retrieve_attribute("SecretAccessKey"))
|
64
|
+
cf.add_output(secret_key)
|
65
|
+
|
66
|
+
output_command = CfFactory::CfOutput.new("FullCommand", "Full command to be executed",
|
67
|
+
CfFactory::CfHelper.join(["/opt/aws/bin/cfn-init -s ", CfFactory::CfHelper.generate_ref("AWS::StackName"),
|
68
|
+
" -r ", launch_config.get_name(),
|
69
|
+
" --access-key ", iam_access_key.generate_ref,
|
70
|
+
" --secret-key ", iam_access_key.retrieve_attribute("SecretAccessKey")]
|
71
|
+
))
|
72
|
+
cf.add_output(output_command)
|
73
|
+
|
74
|
+
tag = CfFactory::CfEc2Tag.new("CloudFormationTests","active")
|
75
|
+
cf.apply_tags_to_all_resources([tag])
|
76
|
+
|
77
|
+
##########################
|
78
|
+
cf_json = cf.generate
|
79
|
+
puts cf_json
|
80
|
+
|
81
|
+
config_options = YAML.load_file("aws_config.yml")
|
82
|
+
config_options["cloud_formation_endpoint"] = "cloudformation.us-east-1.amazonaws.com"
|
83
|
+
validator = CfFactory::TemplateValidation.new(cf_json, config_options)
|
84
|
+
validator.validate()
|
85
|
+
|
data/examples/dynamodb_table.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
|
3
|
-
require 'cf_factory'
|
4
|
-
|
5
|
-
cf = CfFactory::CfMain.new("DynamoTableStack")
|
6
|
-
|
7
|
-
parameter_hash = CfFactory::CfParameter.new("HashKeyName", "Name of the hash key", "String", {"Default" => "hashkey"})
|
8
|
-
cf.add_parameter(parameter_hash)
|
9
|
-
|
10
|
-
dynamo_table = CfFactory::CfDynamoTable.new("DynamoTable",
|
11
|
-
10, 10,
|
12
|
-
parameter_hash.generate_ref, "S")
|
13
|
-
|
14
|
-
cf.add_resource(dynamo_table)
|
15
|
-
|
16
|
-
output_dynamo_table_name = CfFactory::CfOutput.new("DynamoTableName", "The name of the Dynamo table", dynamo_table.generate_ref())
|
17
|
-
cf.add_output(output_dynamo_table_name)
|
18
|
-
|
19
|
-
cf_json = cf.generate
|
20
|
-
puts cf_json
|
21
|
-
|
22
|
-
config_options = YAML.load_file("aws_config.yml")
|
23
|
-
validator = CfFactory::TemplateValidation.new(cf_json, config_options)
|
24
|
-
validator.validate()
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'cf_factory'
|
4
|
+
|
5
|
+
cf = CfFactory::CfMain.new("DynamoTableStack")
|
6
|
+
|
7
|
+
parameter_hash = CfFactory::CfParameter.new("HashKeyName", "Name of the hash key", "String", {"Default" => "hashkey"})
|
8
|
+
cf.add_parameter(parameter_hash)
|
9
|
+
|
10
|
+
dynamo_table = CfFactory::CfDynamoTable.new("DynamoTable",
|
11
|
+
10, 10,
|
12
|
+
parameter_hash.generate_ref, "S")
|
13
|
+
|
14
|
+
cf.add_resource(dynamo_table)
|
15
|
+
|
16
|
+
output_dynamo_table_name = CfFactory::CfOutput.new("DynamoTableName", "The name of the Dynamo table", dynamo_table.generate_ref())
|
17
|
+
cf.add_output(output_dynamo_table_name)
|
18
|
+
|
19
|
+
cf_json = cf.generate
|
20
|
+
puts cf_json
|
21
|
+
|
22
|
+
config_options = YAML.load_file("aws_config.yml")
|
23
|
+
validator = CfFactory::TemplateValidation.new(cf_json, config_options)
|
24
|
+
validator.validate()
|
@@ -1,23 +1,23 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
|
3
|
-
require 'cf_factory'
|
4
|
-
|
5
|
-
cf = CfFactory::CfMain.new("IngestReferenceArchitecture")
|
6
|
-
|
7
|
-
keypair = CfFactory::CfParameter.new("KeyName", "Name of the key",
|
8
|
-
"String", {"Default" => ""})
|
9
|
-
cf.add_parameter(keypair)
|
10
|
-
|
11
|
-
capture_version = CfFactory::CfEbApplicationVersion.new("Capture Version 1", "Capture Version 1", "capture.zip", "1.0")
|
12
|
-
|
13
|
-
capture_option = CfFactory::CfEbOptionSetting.new("aws:autoscaling:launchconfiguration", "EC2KeyName", keypair.generate_ref())
|
14
|
-
|
15
|
-
capture_template = CfFactory::CfEbConfigurationTemplate.new("Capture Template", "Capture Template", [capture_option], :s64ruby193)
|
16
|
-
capture_application = CfFactory::CfEbApplication.new("Capture","Twitter Capture Service",
|
17
|
-
[capture_version], [capture_template])
|
18
|
-
|
19
|
-
cf_json = cf.generate
|
20
|
-
puts cf_json
|
21
|
-
|
22
|
-
validator = CfFactory::TemplateValidation.new(cf_json, config_options)
|
23
|
-
validator.validate()
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'cf_factory'
|
4
|
+
|
5
|
+
cf = CfFactory::CfMain.new("IngestReferenceArchitecture")
|
6
|
+
|
7
|
+
keypair = CfFactory::CfParameter.new("KeyName", "Name of the key",
|
8
|
+
"String", {"Default" => ""})
|
9
|
+
cf.add_parameter(keypair)
|
10
|
+
|
11
|
+
capture_version = CfFactory::CfEbApplicationVersion.new("Capture Version 1", "Capture Version 1", "capture.zip", "1.0")
|
12
|
+
|
13
|
+
capture_option = CfFactory::CfEbOptionSetting.new("aws:autoscaling:launchconfiguration", "EC2KeyName", keypair.generate_ref())
|
14
|
+
|
15
|
+
capture_template = CfFactory::CfEbConfigurationTemplate.new("Capture Template", "Capture Template", [capture_option], :s64ruby193)
|
16
|
+
capture_application = CfFactory::CfEbApplication.new("Capture","Twitter Capture Service",
|
17
|
+
[capture_version], [capture_template])
|
18
|
+
|
19
|
+
cf_json = cf.generate
|
20
|
+
puts cf_json
|
21
|
+
|
22
|
+
validator = CfFactory::TemplateValidation.new(cf_json, config_options)
|
23
|
+
validator.validate()
|