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,20 +1,20 @@
|
|
1
|
-
module CfFactory
|
2
|
-
class CfGenerator
|
3
|
-
def initialize(indent)
|
4
|
-
@indent = indent
|
5
|
-
end
|
6
|
-
|
7
|
-
def self.add_line(indent, input, result)
|
8
|
-
result += "\n#{self.indent(indent, input)}"
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.indent(indent, string)
|
12
|
-
result = ""
|
13
|
-
string.each_line() {|s|
|
14
|
-
result += "#{" "*indent}#{s}"
|
15
|
-
}
|
16
|
-
result
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
1
|
+
module CfFactory
|
2
|
+
class CfGenerator
|
3
|
+
def initialize(indent)
|
4
|
+
@indent = indent
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.add_line(indent, input, result)
|
8
|
+
result += "\n#{self.indent(indent, input)}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.indent(indent, string)
|
12
|
+
result = ""
|
13
|
+
string.each_line() {|s|
|
14
|
+
result += "#{" "*indent}#{s}"
|
15
|
+
}
|
16
|
+
result
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -1,93 +1,93 @@
|
|
1
|
-
module CfFactory
|
2
|
-
class CfHelper
|
3
|
-
def self.generate_ref(cf_object_ref)
|
4
|
-
"{ \"Ref\" : \"#{cf_object_ref}\" }"
|
5
|
-
end
|
6
|
-
|
7
|
-
def self.generate_att(resource_name, attribute_name)
|
8
|
-
"{ \"Fn::GetAtt\" : [ \"#{resource_name}\", \"#{attribute_name}\" ] }"
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.generate_ref_array(cf_array)
|
12
|
-
result = "["
|
13
|
-
cf_array.each() {|cf|
|
14
|
-
result += "#{cf.generate_ref},"
|
15
|
-
}
|
16
|
-
result = result.chomp(",")
|
17
|
-
result += "]"
|
18
|
-
result
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.generate_inner_array(cf_array)
|
22
|
-
result = "["
|
23
|
-
cf_array.each() {|cf|
|
24
|
-
result += "#{cf.generate()},"
|
25
|
-
}
|
26
|
-
result = result.chomp(",")
|
27
|
-
result += "]"
|
28
|
-
result
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.generate_inner_list(cf_array)
|
32
|
-
result = ""
|
33
|
-
cf_array.each() {|cf|
|
34
|
-
result += "#{cf.generate},\n"
|
35
|
-
}
|
36
|
-
result = result.chomp("\n").chomp(",")
|
37
|
-
result
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.base64(string)
|
41
|
-
base = "{ \"Fn::Base64\": \"#{string}\" }"
|
42
|
-
return clean(base)
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.join(array)
|
46
|
-
"{ \"Fn::Join\" : [ \"\", #{print_array(array)} ]}"
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.clean(string)
|
50
|
-
string.gsub(/\"{/,"{").gsub(/\"}/,"}").gsub(/}\"/,"}").gsub(/\"\[/,"[").gsub(/\"\]/,"]")#.gsub(/\\/,"") #TODO: the last gsub invalidated line-breaks
|
51
|
-
end
|
52
|
-
|
53
|
-
def self.availability_zones(string = "")
|
54
|
-
"{ \"Fn::GetAZs\" : \"#{string}\" }"
|
55
|
-
end
|
56
|
-
|
57
|
-
def self.ref_current_region()
|
58
|
-
'{ "Ref" : "AWS::Region" }'
|
59
|
-
end
|
60
|
-
|
61
|
-
def self.az_in_region(az_id = "a", region = "")
|
62
|
-
clean(join([ref_current_region(), az_id]))
|
63
|
-
end
|
64
|
-
|
65
|
-
def self.az_array_in_region(az_ids = ["b","c"], region = "")
|
66
|
-
result = "["
|
67
|
-
az_ids.each() {|az_id|
|
68
|
-
result += CfHelper.az_in_region(az_id)+", "
|
69
|
-
}
|
70
|
-
result = result.chomp(" ").chomp(",")
|
71
|
-
result += "]"
|
72
|
-
end
|
73
|
-
|
74
|
-
def self.print_array(array)
|
75
|
-
inner = ""
|
76
|
-
array.each() {|element|
|
77
|
-
if element == "\n"
|
78
|
-
inner += "\"\\n\" ,"
|
79
|
-
else
|
80
|
-
inner += "\"#{element}\" ,"
|
81
|
-
end
|
82
|
-
}
|
83
|
-
inner.chomp!(",")
|
84
|
-
result = "[ #{inner} ]"
|
85
|
-
#result = array.inspect
|
86
|
-
#puts "rsult before CLEAN = #{result}"
|
87
|
-
res = clean(result)
|
88
|
-
#puts "rsult after CLEAN = #{res}"
|
89
|
-
res
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|
93
|
-
end
|
1
|
+
module CfFactory
|
2
|
+
class CfHelper
|
3
|
+
def self.generate_ref(cf_object_ref)
|
4
|
+
"{ \"Ref\" : \"#{cf_object_ref}\" }"
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.generate_att(resource_name, attribute_name)
|
8
|
+
"{ \"Fn::GetAtt\" : [ \"#{resource_name}\", \"#{attribute_name}\" ] }"
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.generate_ref_array(cf_array)
|
12
|
+
result = "["
|
13
|
+
cf_array.each() {|cf|
|
14
|
+
result += "#{cf.generate_ref},"
|
15
|
+
}
|
16
|
+
result = result.chomp(",")
|
17
|
+
result += "]"
|
18
|
+
result
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.generate_inner_array(cf_array)
|
22
|
+
result = "["
|
23
|
+
cf_array.each() {|cf|
|
24
|
+
result += "#{cf.generate()},"
|
25
|
+
}
|
26
|
+
result = result.chomp(",")
|
27
|
+
result += "]"
|
28
|
+
result
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.generate_inner_list(cf_array)
|
32
|
+
result = ""
|
33
|
+
cf_array.each() {|cf|
|
34
|
+
result += "#{cf.generate},\n"
|
35
|
+
}
|
36
|
+
result = result.chomp("\n").chomp(",")
|
37
|
+
result
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.base64(string)
|
41
|
+
base = "{ \"Fn::Base64\": \"#{string}\" }"
|
42
|
+
return clean(base)
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.join(array)
|
46
|
+
"{ \"Fn::Join\" : [ \"\", #{print_array(array)} ]}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.clean(string)
|
50
|
+
string.gsub(/\"{/,"{").gsub(/\"}/,"}").gsub(/}\"/,"}").gsub(/\"\[/,"[").gsub(/\"\]/,"]")#.gsub(/\\/,"") #TODO: the last gsub invalidated line-breaks
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.availability_zones(string = "")
|
54
|
+
"{ \"Fn::GetAZs\" : \"#{string}\" }"
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.ref_current_region()
|
58
|
+
'{ "Ref" : "AWS::Region" }'
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.az_in_region(az_id = "a", region = "")
|
62
|
+
clean(join([ref_current_region(), az_id]))
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.az_array_in_region(az_ids = ["b","c"], region = "")
|
66
|
+
result = "["
|
67
|
+
az_ids.each() {|az_id|
|
68
|
+
result += CfHelper.az_in_region(az_id)+", "
|
69
|
+
}
|
70
|
+
result = result.chomp(" ").chomp(",")
|
71
|
+
result += "]"
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.print_array(array)
|
75
|
+
inner = ""
|
76
|
+
array.each() {|element|
|
77
|
+
if element == "\n"
|
78
|
+
inner += "\"\\n\" ,"
|
79
|
+
else
|
80
|
+
inner += "\"#{element}\" ,"
|
81
|
+
end
|
82
|
+
}
|
83
|
+
inner.chomp!(",")
|
84
|
+
result = "[ #{inner} ]"
|
85
|
+
#result = array.inspect
|
86
|
+
#puts "rsult before CLEAN = #{result}"
|
87
|
+
res = clean(result)
|
88
|
+
#puts "rsult after CLEAN = #{res}"
|
89
|
+
res
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
@@ -1,74 +1,74 @@
|
|
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
|
-
if (not (value.class.to_s == "String")) and value.method_defined? :get_cf_attributes
|
21
|
-
@result += "#{indent} \"#{key}\" : #{value.get_cf_attributes},\n}"
|
22
|
-
else
|
23
|
-
@result += "#{indent} \"#{key}\" : #{set_quotes(value)},\n"
|
24
|
-
end
|
25
|
-
}
|
26
|
-
|
27
|
-
@result = @result.chomp.chomp(",")
|
28
|
-
@result += "\n#{indent} }"
|
29
|
-
@result += "\n#{indent} }"
|
30
|
-
end
|
31
|
-
|
32
|
-
def generate()
|
33
|
-
indent = " "*additional_indent()
|
34
|
-
@result = "#{indent}"
|
35
|
-
@result += "#{indent}{\n"
|
36
|
-
attributes = self.get_cf_attributes
|
37
|
-
@result += hash_to_string(attributes)
|
38
|
-
|
39
|
-
@result += "\n#{indent} }"
|
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
|
-
|
60
|
-
# Sets leading and trailing quotes
|
61
|
-
def set_quotes(value)
|
62
|
-
if value.class.to_s == "String"
|
63
|
-
if value.delete(" ").start_with?("{") || value.delete(" ").start_with?("[")
|
64
|
-
value
|
65
|
-
else
|
66
|
-
"\"#{value}\""
|
67
|
-
end
|
68
|
-
else
|
69
|
-
value
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
|
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
|
+
if (not (value.class.to_s == "String")) and value.method_defined? :get_cf_attributes
|
21
|
+
@result += "#{indent} \"#{key}\" : #{value.get_cf_attributes},\n}"
|
22
|
+
else
|
23
|
+
@result += "#{indent} \"#{key}\" : #{set_quotes(value)},\n"
|
24
|
+
end
|
25
|
+
}
|
26
|
+
|
27
|
+
@result = @result.chomp.chomp(",")
|
28
|
+
@result += "\n#{indent} }"
|
29
|
+
@result += "\n#{indent} }"
|
30
|
+
end
|
31
|
+
|
32
|
+
def generate()
|
33
|
+
indent = " "*additional_indent()
|
34
|
+
@result = "#{indent}"
|
35
|
+
@result += "#{indent}{\n"
|
36
|
+
attributes = self.get_cf_attributes
|
37
|
+
@result += hash_to_string(attributes)
|
38
|
+
|
39
|
+
@result += "\n#{indent} }"
|
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
|
+
|
60
|
+
# Sets leading and trailing quotes
|
61
|
+
def set_quotes(value)
|
62
|
+
if value.class.to_s == "String"
|
63
|
+
if value.delete(" ").start_with?("{") || value.delete(" ").start_with?("[")
|
64
|
+
value
|
65
|
+
else
|
66
|
+
"\"#{value}\""
|
67
|
+
end
|
68
|
+
else
|
69
|
+
value
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
@@ -1,103 +1,103 @@
|
|
1
|
-
module CfFactory
|
2
|
-
class CfMain
|
3
|
-
def initialize(description, version = "2010-09-09")
|
4
|
-
@description = description
|
5
|
-
@version = version
|
6
|
-
@mappings = []
|
7
|
-
@parameters = []
|
8
|
-
@outputs = []
|
9
|
-
@resources = []
|
10
|
-
end
|
11
|
-
|
12
|
-
# Go through all resources and tag them with the specified array of tags.
|
13
|
-
def apply_tags_to_all_resources(tag_list)
|
14
|
-
@resources.each() {|resource|
|
15
|
-
resource.set_tags(tag_list)
|
16
|
-
}
|
17
|
-
end
|
18
|
-
|
19
|
-
def add_vpc(vpc)
|
20
|
-
@resources << vpc
|
21
|
-
end
|
22
|
-
|
23
|
-
def add_elb(elb)
|
24
|
-
@resources << elb
|
25
|
-
end
|
26
|
-
|
27
|
-
def add_mapping(mapping)
|
28
|
-
@mappings << mapping
|
29
|
-
end
|
30
|
-
|
31
|
-
def add_parameter(parameter)
|
32
|
-
@parameters << parameter
|
33
|
-
end
|
34
|
-
|
35
|
-
def add_output(parameter)
|
36
|
-
@outputs << parameter
|
37
|
-
end
|
38
|
-
|
39
|
-
def add_resource(resource)
|
40
|
-
@resources << resource
|
41
|
-
end
|
42
|
-
|
43
|
-
def generate()
|
44
|
-
@result = "{\n"
|
45
|
-
generate_version
|
46
|
-
generate_description
|
47
|
-
generate_parameters
|
48
|
-
generate_mappings unless @mappings.size == 0
|
49
|
-
generate_resources
|
50
|
-
generate_outputs
|
51
|
-
@result += "}\n"
|
52
|
-
@result
|
53
|
-
end
|
54
|
-
|
55
|
-
private
|
56
|
-
|
57
|
-
def generate_version
|
58
|
-
@result += " \"Description\" : \"#{@description}\",\n"
|
59
|
-
end
|
60
|
-
|
61
|
-
def generate_description
|
62
|
-
@result += " \"AWSTemplateFormatVersion\" : \"#{@version}\",\n"
|
63
|
-
end
|
64
|
-
|
65
|
-
def generate_parameters
|
66
|
-
@result += " \"Parameters\" : {\n"
|
67
|
-
@parameters.each() {|p|
|
68
|
-
@result += p.generate
|
69
|
-
}
|
70
|
-
@result = @result.chomp.chomp(",")
|
71
|
-
@result += "\n },\n"
|
72
|
-
end
|
73
|
-
|
74
|
-
def generate_mappings
|
75
|
-
@result += " \"Mappings\" : {\n"
|
76
|
-
@mappings.each() {|m|
|
77
|
-
@result += m.generate
|
78
|
-
}
|
79
|
-
@result = @result.chomp(",")
|
80
|
-
@result += "\n },\n"
|
81
|
-
end
|
82
|
-
|
83
|
-
def generate_resources
|
84
|
-
@result += " \"Resources\" : {\n"
|
85
|
-
@resources.each() do |resource|
|
86
|
-
@result += resource.generate
|
87
|
-
end
|
88
|
-
@result = @result.chomp.chomp(",")
|
89
|
-
@result += "\n },\n"
|
90
|
-
end
|
91
|
-
|
92
|
-
|
93
|
-
def generate_outputs
|
94
|
-
@result += " \"Outputs\" : {\n"
|
95
|
-
@outputs.each() {|o|
|
96
|
-
@result += o.generate
|
97
|
-
}
|
98
|
-
@result = @result.chomp.chomp(",")
|
99
|
-
@result += "\n }\n"
|
100
|
-
end
|
101
|
-
|
102
|
-
end
|
103
|
-
end
|
1
|
+
module CfFactory
|
2
|
+
class CfMain
|
3
|
+
def initialize(description, version = "2010-09-09")
|
4
|
+
@description = description
|
5
|
+
@version = version
|
6
|
+
@mappings = []
|
7
|
+
@parameters = []
|
8
|
+
@outputs = []
|
9
|
+
@resources = []
|
10
|
+
end
|
11
|
+
|
12
|
+
# Go through all resources and tag them with the specified array of tags.
|
13
|
+
def apply_tags_to_all_resources(tag_list)
|
14
|
+
@resources.each() {|resource|
|
15
|
+
resource.set_tags(tag_list)
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_vpc(vpc)
|
20
|
+
@resources << vpc
|
21
|
+
end
|
22
|
+
|
23
|
+
def add_elb(elb)
|
24
|
+
@resources << elb
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_mapping(mapping)
|
28
|
+
@mappings << mapping
|
29
|
+
end
|
30
|
+
|
31
|
+
def add_parameter(parameter)
|
32
|
+
@parameters << parameter
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_output(parameter)
|
36
|
+
@outputs << parameter
|
37
|
+
end
|
38
|
+
|
39
|
+
def add_resource(resource)
|
40
|
+
@resources << resource
|
41
|
+
end
|
42
|
+
|
43
|
+
def generate()
|
44
|
+
@result = "{\n"
|
45
|
+
generate_version
|
46
|
+
generate_description
|
47
|
+
generate_parameters
|
48
|
+
generate_mappings unless @mappings.size == 0
|
49
|
+
generate_resources
|
50
|
+
generate_outputs
|
51
|
+
@result += "}\n"
|
52
|
+
@result
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def generate_version
|
58
|
+
@result += " \"Description\" : \"#{@description}\",\n"
|
59
|
+
end
|
60
|
+
|
61
|
+
def generate_description
|
62
|
+
@result += " \"AWSTemplateFormatVersion\" : \"#{@version}\",\n"
|
63
|
+
end
|
64
|
+
|
65
|
+
def generate_parameters
|
66
|
+
@result += " \"Parameters\" : {\n"
|
67
|
+
@parameters.each() {|p|
|
68
|
+
@result += p.generate
|
69
|
+
}
|
70
|
+
@result = @result.chomp.chomp(",")
|
71
|
+
@result += "\n },\n"
|
72
|
+
end
|
73
|
+
|
74
|
+
def generate_mappings
|
75
|
+
@result += " \"Mappings\" : {\n"
|
76
|
+
@mappings.each() {|m|
|
77
|
+
@result += m.generate
|
78
|
+
}
|
79
|
+
@result = @result.chomp(",")
|
80
|
+
@result += "\n },\n"
|
81
|
+
end
|
82
|
+
|
83
|
+
def generate_resources
|
84
|
+
@result += " \"Resources\" : {\n"
|
85
|
+
@resources.each() do |resource|
|
86
|
+
@result += resource.generate
|
87
|
+
end
|
88
|
+
@result = @result.chomp.chomp(",")
|
89
|
+
@result += "\n },\n"
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
def generate_outputs
|
94
|
+
@result += " \"Outputs\" : {\n"
|
95
|
+
@outputs.each() {|o|
|
96
|
+
@result += o.generate
|
97
|
+
}
|
98
|
+
@result = @result.chomp.chomp(",")
|
99
|
+
@result += "\n }\n"
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
@@ -1,28 +1,28 @@
|
|
1
|
-
module CfFactory
|
2
|
-
class CfMapping
|
3
|
-
def initialize(name, target, from_to_hash)
|
4
|
-
@name = name
|
5
|
-
@target = target
|
6
|
-
@from_to_hash = from_to_hash
|
7
|
-
end
|
8
|
-
|
9
|
-
def generate
|
10
|
-
@result = ""
|
11
|
-
@result += " \"#{@name}\" : {\n"
|
12
|
-
@from_to_hash.keys.each() {|key|
|
13
|
-
value = @from_to_hash[key]
|
14
|
-
@result += " \"#{key}\"\t : { \"#{@target}\" : \"#{value}\" },\n"
|
15
|
-
}
|
16
|
-
@result = @result.chomp.chomp(",")
|
17
|
-
@result += "\n },"
|
18
|
-
end
|
19
|
-
|
20
|
-
def generate_ref(key)
|
21
|
-
"{\"Fn::FindInMap\" : [ \"#{@name}\", #{CfHelper.generate_ref(key)}, \"#{@target}\" ]}"
|
22
|
-
end
|
23
|
-
|
24
|
-
def map_from_region()
|
25
|
-
"{\"Fn::FindInMap\" : [ \"#{@name}\", \"#{CfHelper.ref_current_region()}\", \"#{@target}\" ]}"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
1
|
+
module CfFactory
|
2
|
+
class CfMapping
|
3
|
+
def initialize(name, target, from_to_hash)
|
4
|
+
@name = name
|
5
|
+
@target = target
|
6
|
+
@from_to_hash = from_to_hash
|
7
|
+
end
|
8
|
+
|
9
|
+
def generate
|
10
|
+
@result = ""
|
11
|
+
@result += " \"#{@name}\" : {\n"
|
12
|
+
@from_to_hash.keys.each() {|key|
|
13
|
+
value = @from_to_hash[key]
|
14
|
+
@result += " \"#{key}\"\t : { \"#{@target}\" : \"#{value}\" },\n"
|
15
|
+
}
|
16
|
+
@result = @result.chomp.chomp(",")
|
17
|
+
@result += "\n },"
|
18
|
+
end
|
19
|
+
|
20
|
+
def generate_ref(key)
|
21
|
+
"{\"Fn::FindInMap\" : [ \"#{@name}\", #{CfHelper.generate_ref(key)}, \"#{@target}\" ]}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def map_from_region()
|
25
|
+
"{\"Fn::FindInMap\" : [ \"#{@name}\", \"#{CfHelper.ref_current_region()}\", \"#{@target}\" ]}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|