cf_factory 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/examples/base_vpc.rb +40 -0
- data/examples/cloudinit_script_for_one_instance.rb +77 -0
- data/examples/cloudinit_script_with_autoscaling.rb +85 -0
- data/examples/elb_with_cloudfront.rb +101 -0
- data/examples/instance_with_eip.rb +38 -0
- data/examples/instance_with_yum.rb +38 -0
- data/examples/just_an_instance.rb +29 -0
- data/examples/play_with_region_and_zones.rb +26 -0
- data/examples/ra_web_hosting.rb +146 -0
- data/examples/s3_with_cloudfront.rb +36 -0
- data/examples/test_vpc.rb +53 -0
- data/lib/cf_factory/as/cf_as_group.rb +75 -0
- data/lib/cf_factory/as/cf_as_launch_config.rb +53 -0
- data/lib/cf_factory/as/cf_as_scaling_policy.rb +33 -0
- data/lib/cf_factory/base/cf_base.rb +97 -0
- data/lib/cf_factory/base/cf_ec2_tag.rb +32 -0
- data/lib/cf_factory/base/cf_generator.rb +18 -0
- data/lib/cf_factory/base/cf_helper.rb +91 -0
- data/lib/cf_factory/base/cf_inner.rb +55 -0
- data/lib/cf_factory/base/cf_main.rb +101 -0
- data/lib/cf_factory/base/cf_mapping.rb +26 -0
- data/lib/cf_factory/base/cf_named_inner.rb +0 -0
- data/lib/cf_factory/base/cf_output.rb +24 -0
- data/lib/cf_factory/base/cf_parameter.rb +25 -0
- data/lib/cf_factory/base/cf_script_reader.rb +32 -0
- data/lib/cf_factory/cloudformation/cf_cloud_formation_init.rb +25 -0
- data/lib/cf_factory/cloudformation/cf_cloudformation_command.rb +37 -0
- data/lib/cf_factory/cloudformation/cf_cloudformation_commands.rb +25 -0
- data/lib/cf_factory/cloudformation/cf_cloudformation_config.rb +33 -0
- data/lib/cf_factory/cloudformation/cf_cloudformation_file.rb +38 -0
- data/lib/cf_factory/cloudformation/cf_cloudformation_files.rb +25 -0
- data/lib/cf_factory/cloudformation/cf_cloudformation_inner.rb +28 -0
- data/lib/cf_factory/cloudformation/cf_cloudformation_package.rb +34 -0
- data/lib/cf_factory/cloudformation/cf_cloudformation_packages.rb +42 -0
- data/lib/cf_factory/cloudformation/cf_cloudformation_sources.rb +30 -0
- data/lib/cf_factory/cloudformation/cf_init_script.rb +73 -0
- data/lib/cf_factory/cloudfront/cf_cache_behavior.rb +37 -0
- data/lib/cf_factory/cloudfront/cf_cache_behaviors.rb +28 -0
- data/lib/cf_factory/cloudfront/cf_cloudfront_distribution.rb +64 -0
- data/lib/cf_factory/cloudfront/cf_custom_origin_config.rb +37 -0
- data/lib/cf_factory/cloudfront/cf_default_cache_behavior.rb +32 -0
- data/lib/cf_factory/cloudfront/cf_distribution_config.rb +31 -0
- data/lib/cf_factory/cloudfront/cf_forwarded_values.rb +25 -0
- data/lib/cf_factory/cloudfront/cf_logging.rb +24 -0
- data/lib/cf_factory/cloudfront/cf_origin.rb +40 -0
- data/lib/cf_factory/cloudfront/cf_s3_origin_config.rb +25 -0
- data/lib/cf_factory/cloudwatch/cf_cloud_watch_alarm.rb +58 -0
- data/lib/cf_factory/ec2/cf_ebs_volume.rb +54 -0
- data/lib/cf_factory/ec2/cf_ec2_instance.rb +62 -0
- data/lib/cf_factory/ec2/cf_ec2_security_group.rb +40 -0
- data/lib/cf_factory/ec2/cf_ec2_security_group_egress.rb +28 -0
- data/lib/cf_factory/ec2/cf_ec2_security_group_ingress.rb +39 -0
- data/lib/cf_factory/ec2/cf_eip.rb +26 -0
- data/lib/cf_factory/ec2/cf_eip_association.rb +29 -0
- data/lib/cf_factory/elb/cf_app_cookie_stickiness_policy.rb +15 -0
- data/lib/cf_factory/elb/cf_elb.rb +49 -0
- data/lib/cf_factory/elb/cf_health_check.rb +23 -0
- data/lib/cf_factory/elb/cf_lb_cookie_stickiness_policy.rb +15 -0
- data/lib/cf_factory/elb/cf_listener.rb +26 -0
- data/lib/cf_factory/help/fixes.rb +14 -0
- data/lib/cf_factory/help/ip_mask.rb +165 -0
- data/lib/cf_factory/help/template_validation.rb +28 -0
- data/lib/cf_factory/iam/cf_iam_access_key.rb +32 -0
- data/lib/cf_factory/iam/cf_iam_group.rb +30 -0
- data/lib/cf_factory/iam/cf_iam_instance_profile.rb +30 -0
- data/lib/cf_factory/iam/cf_iam_policy.rb +18 -0
- data/lib/cf_factory/iam/cf_iam_role.rb +56 -0
- data/lib/cf_factory/iam/cf_iam_statement.rb +23 -0
- data/lib/cf_factory/iam/cf_iam_user.rb +34 -0
- data/lib/cf_factory/iam/cf_policy_document.rb +19 -0
- data/lib/cf_factory/modules/base_vpc.rb +61 -0
- data/lib/cf_factory/rds/cf_rds_instance.rb +53 -0
- data/lib/cf_factory/rds/cf_rds_security_group.rb +33 -0
- data/lib/cf_factory/rds/cf_rds_security_group_ingress.rb +29 -0
- data/lib/cf_factory/rds/cf_rds_subnet_group.rb +29 -0
- data/lib/cf_factory/route53/cf_elb_alias_target.rb +21 -0
- data/lib/cf_factory/route53/cf_record_set.rb +61 -0
- data/lib/cf_factory/route53/cf_route53_record_set.rb +61 -0
- data/lib/cf_factory/route53/cf_route53_record_set_group.rb +42 -0
- data/lib/cf_factory/s3/cf_s3_bucket.rb +32 -0
- data/lib/cf_factory/s3/cf_web_site_config.rb +24 -0
- data/lib/cf_factory/sqs/cf_sqs_queue.rb +26 -0
- data/lib/cf_factory/vpc/cf_attach_gateway.rb +28 -0
- data/lib/cf_factory/vpc/cf_internet_gateway.rb +30 -0
- data/lib/cf_factory/vpc/cf_network_acl.rb +39 -0
- data/lib/cf_factory/vpc/cf_network_acl_association.rb +24 -0
- data/lib/cf_factory/vpc/cf_network_acl_entry.rb +37 -0
- data/lib/cf_factory/vpc/cf_route.rb +43 -0
- data/lib/cf_factory/vpc/cf_route_table.rb +41 -0
- data/lib/cf_factory/vpc/cf_route_table_association.rb +24 -0
- data/lib/cf_factory/vpc/cf_subnet.rb +48 -0
- data/lib/cf_factory/vpc/cf_vpc.rb +64 -0
- data/lib/cf_factory.rb +103 -0
- metadata +140 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
require 'help/include_libraries'
|
|
2
|
+
|
|
3
|
+
cf = CfMain.new("Bla bla bla")
|
|
4
|
+
####### input parameters
|
|
5
|
+
parameter = CfParameter.new("KeyName", "Name of the key", "String", {"Default" => "majung"})
|
|
6
|
+
cf.add_parameter(parameter)
|
|
7
|
+
parameter2 = CfParameter.new("SecurityGroup", "Name of the security group", "String", {"Default" => "Blubber"})
|
|
8
|
+
cf.add_parameter(parameter2)
|
|
9
|
+
|
|
10
|
+
####### mappings
|
|
11
|
+
mapping = CfMapping.new("Default","AMI",{"us-east-1" => "ami-c6699baf", "us-west-2" => "ami-52ff7262"})
|
|
12
|
+
cf.add_mapping(mapping)
|
|
13
|
+
|
|
14
|
+
####### resources
|
|
15
|
+
#vpc
|
|
16
|
+
vpc = CfVpc.new("10.10.0.0/16")
|
|
17
|
+
cf.add_vpc(vpc)
|
|
18
|
+
igw = CfInternetGateway.new("MyInternetGateway", vpc)
|
|
19
|
+
vpc.add_internet_gateway(igw)
|
|
20
|
+
route_table = CfRouteTable.new("MyRouteTable")
|
|
21
|
+
vpc.add_route_table(route_table)
|
|
22
|
+
route1 = CfRoute.new("MyRoute1", "88.44.22.11/32", igw)
|
|
23
|
+
route2 = CfRoute.new("MyRoute2", "188.144.122.111/32", igw)
|
|
24
|
+
route_table.add_route(route1)
|
|
25
|
+
route_table.add_route(route2)
|
|
26
|
+
|
|
27
|
+
network_acl = CfNetworkAcl.new("MyAcl1")
|
|
28
|
+
vpc.add_network_acl(network_acl)
|
|
29
|
+
network_acl_entry = CfNetworkAclEntry.new("Acl1", "110", "6", "ALLOW", false, "0.0.0.0/0", 80, 80)
|
|
30
|
+
network_acl.add_network_acl_entry(network_acl_entry)
|
|
31
|
+
|
|
32
|
+
subnet1 = CfSubnet.new("WebTier1", "10.10.0.0/24", "eu-west-1a", route_table, network_acl)
|
|
33
|
+
vpc.add_subnet(subnet1)
|
|
34
|
+
subnet2 = CfSubnet.new("AppTier1", "10.10.1.0/24", "eu-west-1a", route_table, network_acl)
|
|
35
|
+
vpc.add_subnet(subnet2)
|
|
36
|
+
subnet3 = CfSubnet.new("DbTier1", "10.10.2.0/24", "eu-west-1a", route_table, network_acl)
|
|
37
|
+
vpc.add_subnet(subnet2)
|
|
38
|
+
|
|
39
|
+
#elb
|
|
40
|
+
#elb = CfElb.new("MyElb", {
|
|
41
|
+
# :availability_zones => "eu-west-1",
|
|
42
|
+
# :app_cookie_stickiness_policy => CfAppCookieStickinessPolicy.new("cookie-name","policy bla")})
|
|
43
|
+
#cf.add_elb(elb)
|
|
44
|
+
#puts elb.get_cf_properties()
|
|
45
|
+
|
|
46
|
+
####### output parameters
|
|
47
|
+
output = CfOutput.new("VPC_ID", "Id of the VPC", vpc.generate_ref())
|
|
48
|
+
cf.add_output(output)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
puts cf.generate
|
|
52
|
+
|
|
53
|
+
#puts "the reference for the VPC : #{vpc.generate_ref}"
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
require 'cf_factory/base/cf_base'
|
|
2
|
+
require 'cf_factory/base/cf_helper'
|
|
3
|
+
|
|
4
|
+
class CfAsGroup
|
|
5
|
+
include CfBase
|
|
6
|
+
|
|
7
|
+
def initialize(name, availability_zones, launch_config, load_balancers, max_size, min_size, options)
|
|
8
|
+
@name = name
|
|
9
|
+
@availability_zones = availability_zones
|
|
10
|
+
@launch_config = launch_config
|
|
11
|
+
@load_balancers = load_balancers
|
|
12
|
+
@max_size = max_size
|
|
13
|
+
@min_size = min_size
|
|
14
|
+
|
|
15
|
+
@cooldown = options[:cooldown]
|
|
16
|
+
@desired_capacity = options[:desired_capacity]
|
|
17
|
+
@health_check_grace_period = options[:health_check_grace_period]
|
|
18
|
+
@health_check_type = options[:health_check_type]
|
|
19
|
+
#TODO: NotificationConfiguration
|
|
20
|
+
@subnets = options[:subnets]
|
|
21
|
+
validate()
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def set_tags(tag_list)
|
|
25
|
+
@tag_list = []
|
|
26
|
+
tag_list.each() {|tg|
|
|
27
|
+
tg2 = tg.clone
|
|
28
|
+
tg2.set_propagate_at_launch(true)
|
|
29
|
+
puts ">>>>>>>>>>>>>>>>>>>>> "+tg2.inspect
|
|
30
|
+
@tag_list << tg2
|
|
31
|
+
}
|
|
32
|
+
@tag_list
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def validate
|
|
36
|
+
if @max_size < @min_size
|
|
37
|
+
raise Exception.new("max size (#{@max_size}) must be equal or larger min size (#{@min_size})")
|
|
38
|
+
end
|
|
39
|
+
if @health_check_type == "ELB" && @health_check_grace_period.nil?
|
|
40
|
+
raise Exception.new("HealthCheckGracePeriod must be specified for ElasticLoadBalancer based health checks.")
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def get_cf_type
|
|
45
|
+
"AWS::AutoScaling::AutoScalingGroup"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def get_cf_attributes
|
|
49
|
+
{}
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def get_cf_properties
|
|
53
|
+
result = {"AvailabilityZones" => @availability_zones,
|
|
54
|
+
"LaunchConfigurationName" => @launch_config.generate_ref,
|
|
55
|
+
"LoadBalancerNames" => CfHelper.generate_ref_array(@load_balancers),
|
|
56
|
+
"MaxSize" => @max_size,
|
|
57
|
+
"MinSize" => @min_size
|
|
58
|
+
}
|
|
59
|
+
result["Cooldown"] = @cooldown unless @cooldown.nil?
|
|
60
|
+
result["DesiredCapacity"] = @desired_capacity unless @desired_capacity.nil?
|
|
61
|
+
result["HealthCheckGracePeriod"] = @health_check_grace_period.to_i unless @health_check_grace_period.nil?
|
|
62
|
+
result["HealthCheckType"] = @health_check_type unless @health_check_type.nil?
|
|
63
|
+
result["VPCZoneIdentifier"] = CfHelper.generate_ref_array(@subnets) unless @subnets.nil?
|
|
64
|
+
result
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def add_ingress_rule(ingress_rule)
|
|
68
|
+
@ingress_rules << ingress_rule
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def add_egress_rule(egress_rule)
|
|
72
|
+
@egress_rules << egress_rule
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
require 'cf_factory/base/cf_base'
|
|
2
|
+
require 'cf_factory/base/cf_helper'
|
|
3
|
+
|
|
4
|
+
class CfAsLaunchConfig
|
|
5
|
+
include CfBase
|
|
6
|
+
|
|
7
|
+
def initialize(name, image_id, instance_type, options)
|
|
8
|
+
@name = name
|
|
9
|
+
@image_id = image_id
|
|
10
|
+
@instance_type = instance_type
|
|
11
|
+
|
|
12
|
+
@user_data = options[:user_data]
|
|
13
|
+
@key_name = options[:key_name]
|
|
14
|
+
@security_groups = options[:security_groups]
|
|
15
|
+
@spot_price = options[:spot_price]
|
|
16
|
+
#TODO: a couple of properties missing
|
|
17
|
+
validate()
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def get_cf_type
|
|
21
|
+
"AWS::AutoScaling::LaunchConfiguration"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def get_cf_attributes
|
|
25
|
+
super
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def get_cf_properties
|
|
29
|
+
result = {"ImageId" => @image_id,
|
|
30
|
+
"InstanceType" => @instance_type
|
|
31
|
+
}
|
|
32
|
+
result["UserData"] = CfHelper.base64(@user_data) unless @user_data.nil?
|
|
33
|
+
result["KeyName"] = @key_name unless @key_name.nil?
|
|
34
|
+
result["SecurityGroups"] = CfHelper.generate_ref_array(@security_groups) unless @security_groups.nil?
|
|
35
|
+
result["SpotPrice"] = @spot_price unless @spot_price.nil?
|
|
36
|
+
result
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def add_ingress_rule(ingress_rule)
|
|
40
|
+
@ingress_rules << ingress_rule
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def add_egress_rule(egress_rule)
|
|
44
|
+
@egress_rules << egress_rule
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
private
|
|
48
|
+
|
|
49
|
+
def validate
|
|
50
|
+
raise Exception.new("instance type #{@instance_type} is not supported") unless CfEc2Instance::SUPPORTED_TYPES.include?(@instance_type)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'cf_factory/base/cf_base'
|
|
2
|
+
require 'cf_factory/base/cf_helper'
|
|
3
|
+
|
|
4
|
+
class CfAsScalingPolicy
|
|
5
|
+
include CfBase
|
|
6
|
+
|
|
7
|
+
def initialize(name, auto_scaling_group, adjustment_type, scaling_adjustment, options = {})
|
|
8
|
+
@name = name
|
|
9
|
+
@auto_scaling_group = auto_scaling_group
|
|
10
|
+
@adjustment_type = adjustment_type
|
|
11
|
+
@scaling_adjustment = scaling_adjustment
|
|
12
|
+
@cooldown = options[:cooldown]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def get_cf_type
|
|
16
|
+
"AWS::AutoScaling::ScalingPolicy"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def get_cf_attributes
|
|
20
|
+
{}
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def get_cf_properties
|
|
24
|
+
result = {
|
|
25
|
+
"AutoScalingGroupName" => @auto_scaling_group.generate_ref,
|
|
26
|
+
"AdjustmentType" => @adjustment_type,
|
|
27
|
+
"ScalingAdjustment" => @scaling_adjustment
|
|
28
|
+
}
|
|
29
|
+
result["Cooldown"] = @cooldown unless @cooldown.nil?
|
|
30
|
+
result
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
require 'cf_factory/base/cf_helper'
|
|
2
|
+
|
|
3
|
+
module CfBase
|
|
4
|
+
def get_name
|
|
5
|
+
@name
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def get_cf_type
|
|
9
|
+
raise Exception.new("must be defined")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def get_deletion_policy
|
|
13
|
+
@deletion_policy
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def get_cf_attributes
|
|
17
|
+
result = {}
|
|
18
|
+
result["Metadata"] = @meta_data.generate unless @meta_data.nil?
|
|
19
|
+
result
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def get_cf_properties
|
|
23
|
+
raise Exception.new("must be defined")
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def generate_ref
|
|
27
|
+
CfHelper.generate_ref(self.get_name)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def retrieve_attribute(attribute)
|
|
31
|
+
CfHelper.generate_att(@name, attribute)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def set_meta_data(meta_data)
|
|
35
|
+
@meta_data = meta_data
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def set_tags(tag_list)
|
|
39
|
+
#should be overwritten by those resources that support tags
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def hash_to_string(hash, indent=0)
|
|
43
|
+
output = ""
|
|
44
|
+
hash.keys.each() do |key|
|
|
45
|
+
value = hash[key]
|
|
46
|
+
output += " " * indent
|
|
47
|
+
case value.class.to_s
|
|
48
|
+
when "Hash"
|
|
49
|
+
output += " \"#{key}\" : \n{#{hash_to_string(value,indent+5)}},\n"
|
|
50
|
+
else
|
|
51
|
+
output += " \"#{key}\" : #{set_quotes(value)},\n"
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
output
|
|
55
|
+
output = output.chomp().chomp(",")
|
|
56
|
+
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def generate
|
|
60
|
+
@result = ""
|
|
61
|
+
@result += " \"#{@name}\" : {\n"
|
|
62
|
+
unless self.get_cf_type() == nil
|
|
63
|
+
@result += " \"Type\" : \"#{self.get_cf_type()}\",\n"
|
|
64
|
+
end
|
|
65
|
+
unless self.get_deletion_policy() == nil
|
|
66
|
+
@result += " \"DeletionPolicy\" : \"#{self.get_deletion_policy()}\",\n"
|
|
67
|
+
end
|
|
68
|
+
attributes = self.get_cf_attributes
|
|
69
|
+
unless attributes.size == 0
|
|
70
|
+
@result += "#{hash_to_string(attributes)},\n"
|
|
71
|
+
end
|
|
72
|
+
#
|
|
73
|
+
properties = self.get_cf_properties
|
|
74
|
+
properties["Tags"] = CfHelper.generate_inner_array(@tag_list) unless @tag_list.nil?
|
|
75
|
+
unless properties.size == 0
|
|
76
|
+
@result += " \"Properties\" : {\n"
|
|
77
|
+
@result += hash_to_string(properties)
|
|
78
|
+
@result += "\n }"
|
|
79
|
+
end
|
|
80
|
+
@result = @result.chomp.chomp(",")
|
|
81
|
+
@result += "\n },\n"
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Sets leading and trailing quotes
|
|
85
|
+
def set_quotes(value)
|
|
86
|
+
if value.class.to_s == "String"
|
|
87
|
+
if value.delete(" ").start_with?("{") || value.delete(" ").start_with?("[")
|
|
88
|
+
value
|
|
89
|
+
else
|
|
90
|
+
"\"#{value}\""
|
|
91
|
+
end
|
|
92
|
+
else
|
|
93
|
+
value
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'cf_factory/base/cf_inner'
|
|
2
|
+
|
|
3
|
+
class CfEc2Tag
|
|
4
|
+
include CfInner
|
|
5
|
+
|
|
6
|
+
def initialize(key, value, options = {})
|
|
7
|
+
@key = key
|
|
8
|
+
@value = value
|
|
9
|
+
@propagate_at_launch = options[:propagate_at_launch]
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def set_propagate_at_launch(pal)
|
|
13
|
+
@propagate_at_launch = pal
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def get_cf_attributes
|
|
17
|
+
result = {"Key" => @key,
|
|
18
|
+
"Value" => @value
|
|
19
|
+
}
|
|
20
|
+
result["PropagateAtLaunch"] = @propagate_at_launch unless @propagate_at_launch.nil?
|
|
21
|
+
result
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def clone
|
|
25
|
+
options = {}
|
|
26
|
+
if @propagate_at_launch
|
|
27
|
+
options[:propagate_at_launch] = @propagate_at_launch
|
|
28
|
+
end
|
|
29
|
+
CfEc2Tag.new(@key,@value,options)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
class CfGenerator
|
|
2
|
+
def initialize(indent)
|
|
3
|
+
@indent = indent
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def self.add_line(indent, input, result)
|
|
7
|
+
result += "\n#{self.indent(indent, input)}"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.indent(indent, string)
|
|
11
|
+
result = ""
|
|
12
|
+
string.each_line() {|s|
|
|
13
|
+
result += "#{" "*indent}#{s}"
|
|
14
|
+
}
|
|
15
|
+
result
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
class CfHelper
|
|
2
|
+
def self.generate_ref(cf_object_ref)
|
|
3
|
+
"{ \"Ref\" : \"#{cf_object_ref}\" }"
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def self.generate_att(resource_name, attribute_name)
|
|
7
|
+
"{ \"Fn::GetAtt\" : [ \"#{resource_name}\", \"#{attribute_name}\" ] }"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.generate_ref_array(cf_array)
|
|
11
|
+
result = "["
|
|
12
|
+
cf_array.each() {|cf|
|
|
13
|
+
result += "#{cf.generate_ref},"
|
|
14
|
+
}
|
|
15
|
+
result = result.chomp(",")
|
|
16
|
+
result += "]"
|
|
17
|
+
result
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.generate_inner_array(cf_array)
|
|
21
|
+
result = "["
|
|
22
|
+
cf_array.each() {|cf|
|
|
23
|
+
result += "#{cf.generate()},"
|
|
24
|
+
}
|
|
25
|
+
result = result.chomp(",")
|
|
26
|
+
result += "]"
|
|
27
|
+
result
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.generate_inner_list(cf_array)
|
|
31
|
+
result = ""
|
|
32
|
+
cf_array.each() {|cf|
|
|
33
|
+
result += "#{cf.generate},\n"
|
|
34
|
+
}
|
|
35
|
+
result = result.chomp("\n").chomp(",")
|
|
36
|
+
result
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def self.base64(string)
|
|
40
|
+
base = "{ \"Fn::Base64\": \"#{string}\" }"
|
|
41
|
+
return clean(base)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def self.join(array)
|
|
45
|
+
"{ \"Fn::Join\" : [ \"\", #{print_array(array)} ]}"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def self.clean(string)
|
|
49
|
+
string.gsub(/\"{/,"{").gsub(/\"}/,"}").gsub(/}\"/,"}").gsub(/\"\[/,"[").gsub(/\"\]/,"]")#.gsub(/\\/,"") #TODO: the last gsub invalidated line-breaks
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def self.availability_zones(string = "")
|
|
53
|
+
"{ \"Fn::GetAZs\" : \"#{string}\" }"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def self.ref_current_region()
|
|
57
|
+
'{ "Ref" : "AWS::Region" }'
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def self.az_in_region(az_id = "a", region = "")
|
|
61
|
+
clean(join([ref_current_region(), az_id]))
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def self.az_array_in_region(az_ids = ["b","c"], region = "")
|
|
65
|
+
result = "["
|
|
66
|
+
az_ids.each() {|az_id|
|
|
67
|
+
result += CfHelper.az_in_region(az_id)+", "
|
|
68
|
+
}
|
|
69
|
+
result = result.chomp(" ").chomp(",")
|
|
70
|
+
result += "]"
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def self.print_array(array)
|
|
74
|
+
inner = ""
|
|
75
|
+
array.each() {|element|
|
|
76
|
+
if element == "\n"
|
|
77
|
+
inner += "\"\\n\" ,"
|
|
78
|
+
else
|
|
79
|
+
inner += "\"#{element}\" ,"
|
|
80
|
+
end
|
|
81
|
+
}
|
|
82
|
+
inner.chomp!(",")
|
|
83
|
+
result = "[ #{inner} ]"
|
|
84
|
+
#result = array.inspect
|
|
85
|
+
#puts "rsult before CLEAN = #{result}"
|
|
86
|
+
res = clean(result)
|
|
87
|
+
#puts "rsult after CLEAN = #{res}"
|
|
88
|
+
res
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require 'cf_factory/base/cf_helper'
|
|
2
|
+
|
|
3
|
+
module CfInner
|
|
4
|
+
def get_cf_attributes
|
|
5
|
+
raise Exception.new("must be defined")
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def additional_indent
|
|
9
|
+
0
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def generate_name()
|
|
13
|
+
indent = " "*additional_indent()
|
|
14
|
+
@result = "#{indent}"
|
|
15
|
+
@result += "#{indent}{\n"
|
|
16
|
+
attributes = self.get_cf_attributes
|
|
17
|
+
@result += "#{indent} \"#{@name}\" : {\n"
|
|
18
|
+
attributes.keys.each() {|key|
|
|
19
|
+
value = attributes[key]
|
|
20
|
+
@result += "#{indent} \"#{key}\" : #{set_quotes(value)},\n"
|
|
21
|
+
}
|
|
22
|
+
#
|
|
23
|
+
@result = @result.chomp.chomp(",")
|
|
24
|
+
@result += "\n#{indent} }"
|
|
25
|
+
@result += "\n#{indent} }"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def generate()
|
|
29
|
+
indent = " "*additional_indent()
|
|
30
|
+
@result = "#{indent}"
|
|
31
|
+
@result += "#{indent}{\n"
|
|
32
|
+
attributes = self.get_cf_attributes
|
|
33
|
+
attributes.keys.each() {|key|
|
|
34
|
+
value = attributes[key]
|
|
35
|
+
@result += "#{indent} \"#{key}\" : #{set_quotes(value)},\n"
|
|
36
|
+
}
|
|
37
|
+
#
|
|
38
|
+
@result = @result.chomp.chomp(",")
|
|
39
|
+
@result += "\n#{indent} }"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Sets leading and trailing quotes
|
|
43
|
+
def set_quotes(value)
|
|
44
|
+
if value.class.to_s == "String"
|
|
45
|
+
if value.delete(" ").start_with?("{") || value.delete(" ").start_with?("[")
|
|
46
|
+
value
|
|
47
|
+
else
|
|
48
|
+
"\"#{value}\""
|
|
49
|
+
end
|
|
50
|
+
else
|
|
51
|
+
value
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
class CfMain
|
|
2
|
+
def initialize(description, version = "2010-09-09")
|
|
3
|
+
@description = description
|
|
4
|
+
@version = version
|
|
5
|
+
@mappings = []
|
|
6
|
+
@parameters = []
|
|
7
|
+
@outputs = []
|
|
8
|
+
@resources = []
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Go through all resources and tag them with the specified array of tags.
|
|
12
|
+
def apply_tags_to_all_resources(tag_list)
|
|
13
|
+
@resources.each() {|resource|
|
|
14
|
+
resource.set_tags(tag_list)
|
|
15
|
+
}
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def add_vpc(vpc)
|
|
19
|
+
@resources << vpc
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def add_elb(elb)
|
|
23
|
+
@resources << elb
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def add_mapping(mapping)
|
|
27
|
+
@mappings << mapping
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def add_parameter(parameter)
|
|
31
|
+
@parameters << parameter
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def add_output(parameter)
|
|
35
|
+
@outputs << parameter
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def add_resource(resource)
|
|
39
|
+
@resources << resource
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def generate()
|
|
43
|
+
@result = "{\n"
|
|
44
|
+
generate_version
|
|
45
|
+
generate_description
|
|
46
|
+
generate_parameters
|
|
47
|
+
generate_mappings unless @mappings.size == 0
|
|
48
|
+
generate_resources
|
|
49
|
+
generate_outputs
|
|
50
|
+
@result += "}\n"
|
|
51
|
+
@result
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
private
|
|
55
|
+
|
|
56
|
+
def generate_version
|
|
57
|
+
@result += " \"Description\" : \"#{@description}\",\n"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def generate_description
|
|
61
|
+
@result += " \"AWSTemplateFormatVersion\" : \"#{@version}\",\n"
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def generate_parameters
|
|
65
|
+
@result += " \"Parameters\" : {\n"
|
|
66
|
+
@parameters.each() {|p|
|
|
67
|
+
@result += p.generate
|
|
68
|
+
}
|
|
69
|
+
@result = @result.chomp.chomp(",")
|
|
70
|
+
@result += "\n },\n"
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def generate_mappings
|
|
74
|
+
@result += " \"Mappings\" : {\n"
|
|
75
|
+
@mappings.each() {|m|
|
|
76
|
+
@result += m.generate
|
|
77
|
+
}
|
|
78
|
+
@result = @result.chomp(",")
|
|
79
|
+
@result += "\n },\n"
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def generate_resources
|
|
83
|
+
@result += " \"Resources\" : {\n"
|
|
84
|
+
@resources.each() do |resource|
|
|
85
|
+
@result += resource.generate
|
|
86
|
+
end
|
|
87
|
+
@result = @result.chomp.chomp(",")
|
|
88
|
+
@result += "\n },\n"
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def generate_outputs
|
|
93
|
+
@result += " \"Outputs\" : {\n"
|
|
94
|
+
@outputs.each() {|o|
|
|
95
|
+
@result += o.generate
|
|
96
|
+
}
|
|
97
|
+
@result = @result.chomp.chomp(",")
|
|
98
|
+
@result += "\n }\n"
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
class CfMapping
|
|
2
|
+
def initialize(name, target, from_to_hash)
|
|
3
|
+
@name = name
|
|
4
|
+
@target = target
|
|
5
|
+
@from_to_hash = from_to_hash
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def generate
|
|
9
|
+
@result = ""
|
|
10
|
+
@result += " \"#{@name}\" : {\n"
|
|
11
|
+
@from_to_hash.keys.each() {|key|
|
|
12
|
+
value = @from_to_hash[key]
|
|
13
|
+
@result += " \"#{key}\"\t : { \"#{@target}\" : \"#{value}\" },\n"
|
|
14
|
+
}
|
|
15
|
+
@result = @result.chomp.chomp(",")
|
|
16
|
+
@result += "\n },"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def generate_ref(key)
|
|
20
|
+
"{\"Fn::FindInMap\" : [ \"#{@name}\", #{CfHelper.generate_ref(key)}, \"#{@target}\" ]}"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def map_from_region()
|
|
24
|
+
"{\"Fn::FindInMap\" : [ \"#{@name}\", \"#{CfHelper.ref_current_region()}\", \"#{@target}\" ]}"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
File without changes
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'cf_factory/base/cf_base'
|
|
2
|
+
|
|
3
|
+
class CfOutput
|
|
4
|
+
include CfBase
|
|
5
|
+
|
|
6
|
+
def initialize(name, description, value)
|
|
7
|
+
@name = name
|
|
8
|
+
@description = description
|
|
9
|
+
@value = value
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def get_cf_type
|
|
13
|
+
nil
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def get_cf_attributes
|
|
17
|
+
{"Description" => @description, "Value" => @value}
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def get_cf_properties
|
|
21
|
+
{}
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'cf_factory/base/cf_base'
|
|
2
|
+
|
|
3
|
+
class CfParameter
|
|
4
|
+
include CfBase
|
|
5
|
+
|
|
6
|
+
def initialize(name, description, type, properties_hash = {})
|
|
7
|
+
@name = name
|
|
8
|
+
@description = description
|
|
9
|
+
@type = type
|
|
10
|
+
@properties_hash = properties_hash
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def get_cf_type
|
|
14
|
+
@type
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def get_cf_attributes
|
|
18
|
+
@properties_hash.merge({"Description" => @description})
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def get_cf_properties
|
|
22
|
+
{}
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|