cloud_former 0.4.9 → 0.4.10
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d18c4dc7c67ad9101295cb778dea8927aa3b726e
|
4
|
+
data.tar.gz: 26e157b3e3ac58cc30e75c4466f76792a6a908c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b713ab3240f3fb71c809247ed054f858fc12d329640bc69a985d6de6b490ae51fee400a1ea4b3566a82028245722bc9fb1a21f324dbb960a10a1c732f0b1b59
|
7
|
+
data.tar.gz: 042136f901246e7c593f589acb7e21aaec4120d46ee44d03abfcb9704f8605b960e494e5ea4b5ca2eed0811625020237b69dae92b4c2331b7fff968e8ffd9a7a
|
@@ -5,6 +5,14 @@ module CloudFormer
|
|
5
5
|
base.extend ClassMethods
|
6
6
|
end
|
7
7
|
|
8
|
+
def nested_resources
|
9
|
+
@nested_resources ||= []
|
10
|
+
end
|
11
|
+
|
12
|
+
def resource_tree
|
13
|
+
[self, nested_resources.map(&:resource_tree)]
|
14
|
+
end
|
15
|
+
|
8
16
|
module ClassMethods
|
9
17
|
|
10
18
|
def aws_property(name, options={})
|
@@ -53,37 +61,60 @@ module CloudFormer
|
|
53
61
|
end
|
54
62
|
|
55
63
|
def make_aws_accessor(name, options)
|
56
|
-
define_method(name) do |
|
57
|
-
if
|
58
|
-
if options[:
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
64
|
+
define_method(name) do |*args, &block|
|
65
|
+
if block
|
66
|
+
if options[:type] < CloudFormer::ResourceProperty || options[:type] < CloudFormer::Resource
|
67
|
+
value = if options[:list]
|
68
|
+
count = args.shift
|
69
|
+
count.times.map do |i|
|
70
|
+
instance = options[:type].new(*args) { instance_exec(i, &block) }
|
71
|
+
self.nested_resources << instance if instance.is_a?(CloudFormer::Resource)
|
72
|
+
instance
|
73
|
+
end
|
74
|
+
else
|
75
|
+
instance = options[:type].new(*args, &block)
|
76
|
+
self.nested_resources << instance if instance.is_a?(CloudFormer::Resource)
|
77
|
+
instance
|
63
78
|
end
|
79
|
+
else
|
80
|
+
raise ArgumentError, "Can't construct #{options[:type]} using block syntax."
|
64
81
|
end
|
82
|
+
instance_variable_set("@#{name}", value)
|
83
|
+
else
|
84
|
+
if args.size == 1
|
85
|
+
val = args.first
|
86
|
+
if options[:list] && !val.respond_to?(:each)
|
87
|
+
if (!val.respond_to?(:acts_as_list?) || !val.acts_as_list?) && options[:list] != :ok
|
88
|
+
raise ArgumentError.new(
|
89
|
+
"A list is required for #{name} in #{self.class.name}, but a #{val.class.name} was given."
|
90
|
+
)
|
91
|
+
end
|
92
|
+
end
|
65
93
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
94
|
+
if options[:list]
|
95
|
+
unless val.respond_to?(:acts_as_list?) && val.acts_as_list?
|
96
|
+
if options[:list] == :ok
|
97
|
+
if val.respond_to?(:each)
|
98
|
+
val.each do |item|
|
99
|
+
self.class.check_type_of_aws_value(name, item, options)
|
100
|
+
end
|
101
|
+
else
|
102
|
+
self.class.check_type_of_aws_value(name, val, options)
|
103
|
+
end
|
104
|
+
else
|
70
105
|
val.each do |item|
|
71
106
|
self.class.check_type_of_aws_value(name, item, options)
|
72
107
|
end
|
73
|
-
else
|
74
|
-
self.class.check_type_of_aws_value(name, val, options)
|
75
|
-
end
|
76
|
-
else
|
77
|
-
val.each do |item|
|
78
|
-
self.class.check_type_of_aws_value(name, item, options)
|
79
108
|
end
|
80
109
|
end
|
110
|
+
else
|
111
|
+
self.class.check_type_of_aws_value(name, val, options)
|
81
112
|
end
|
82
|
-
else
|
83
|
-
self.class.check_type_of_aws_value(name, val, options)
|
84
|
-
end
|
85
113
|
|
86
|
-
|
114
|
+
instance_variable_set("@#{name}", val)
|
115
|
+
elsif args.size > 1
|
116
|
+
raise ArgumentError, "wrong number of arguments (#{args.size} for 0..1)"
|
117
|
+
end
|
87
118
|
end
|
88
119
|
|
89
120
|
if instance_variable_defined?("@#{name}")
|
@@ -6,23 +6,27 @@ module CloudFormer
|
|
6
6
|
|
7
7
|
json_attribute :aws_type, name: 'Type'
|
8
8
|
|
9
|
-
attr_reader :name
|
10
9
|
attr_reader :aws_type
|
11
10
|
attr_reader :metadata_items
|
12
11
|
|
13
12
|
aws_attribute :depends_on, list: true, type: String
|
14
13
|
aws_attribute :deletion_policy, type: String
|
15
14
|
|
16
|
-
def initialize(name, &block)
|
15
|
+
def initialize(name=nil, &block)
|
17
16
|
@name = name
|
18
|
-
if name.nil? || name.empty?
|
19
|
-
raise ArgumentError.new("Attempting to create a resource of type #{self.class.name} with no name")
|
20
|
-
end
|
21
17
|
@metadata_items = []
|
22
18
|
@aws_type = self.class.name.sub('CloudFormer', 'AWS')
|
23
19
|
if block_given?
|
24
20
|
self.instance_eval(&block)
|
25
21
|
end
|
22
|
+
if @name.nil? || @name.empty?
|
23
|
+
raise ArgumentError.new("Attempting to create a resource of type #{self.class.name} with no name")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def name(arg=nil)
|
28
|
+
@name = arg if arg
|
29
|
+
@name
|
26
30
|
end
|
27
31
|
|
28
32
|
def add_metadata(metadata)
|
@@ -33,7 +33,9 @@ module CloudFormer
|
|
33
33
|
if @resources.any?
|
34
34
|
resource_res = {}
|
35
35
|
@resources.each do |resource|
|
36
|
-
|
36
|
+
resource.resource_tree.flatten.each do |r|
|
37
|
+
resource_res[r.name] = r.dump_json
|
38
|
+
end
|
37
39
|
end
|
38
40
|
res['Resources'] = resource_res
|
39
41
|
end
|
data/lib/cloud_former/version.rb
CHANGED
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CloudFormer::HasPropertiesAndAttributes do
|
4
|
+
let(:template) { CloudFormer::Template.new }
|
5
|
+
|
6
|
+
it "builds simple resources correctly" do
|
7
|
+
instance = CloudFormer::EC2::Instance.new('myinstance') do
|
8
|
+
availability_zone 'us-east-1'
|
9
|
+
image_id 'ami-123456'
|
10
|
+
end
|
11
|
+
template.add_resource(instance)
|
12
|
+
|
13
|
+
expect(template.dump_json).to eq(
|
14
|
+
"AWSTemplateFormatVersion" => "2010-09-09",
|
15
|
+
"Resources" => {
|
16
|
+
"myinstance" => {
|
17
|
+
"Type" => "AWS::EC2::Instance",
|
18
|
+
"Properties" => {
|
19
|
+
"AvailabilityZone" => "us-east-1",
|
20
|
+
"ImageId" => "ami-123456",
|
21
|
+
},
|
22
|
+
},
|
23
|
+
},
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "supports builds nested resource lists via blocks" do
|
28
|
+
auto_scaling_group = CloudFormer::AutoScaling::LaunchConfiguration.new('myconfig') do
|
29
|
+
image_id 'ami-123456'
|
30
|
+
security_groups(2) do |i|
|
31
|
+
name "name #{i}"
|
32
|
+
group_description "security group #{i}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
template.add_resource(auto_scaling_group)
|
36
|
+
|
37
|
+
expect(template.dump_json).to eq(
|
38
|
+
"AWSTemplateFormatVersion" => "2010-09-09",
|
39
|
+
"Resources" => {
|
40
|
+
"myconfig" => {
|
41
|
+
"Type" => "AWS::AutoScaling::LaunchConfiguration",
|
42
|
+
"Properties" => {
|
43
|
+
"ImageId" => "ami-123456",
|
44
|
+
"SecurityGroups" => [
|
45
|
+
{"Ref" => "name 0"},
|
46
|
+
{"Ref" => "name 1"},
|
47
|
+
],
|
48
|
+
},
|
49
|
+
},
|
50
|
+
"name 0" => {
|
51
|
+
"Type" => "AWS::EC2::SecurityGroup",
|
52
|
+
"Properties" => {
|
53
|
+
"GroupDescription" => "security group 0",
|
54
|
+
},
|
55
|
+
},
|
56
|
+
"name 1" => {
|
57
|
+
"Type" => "AWS::EC2::SecurityGroup",
|
58
|
+
"Properties" => {
|
59
|
+
"GroupDescription" => "security group 1",
|
60
|
+
},
|
61
|
+
},
|
62
|
+
},
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "supports builds nested resource properties via blocks" do
|
67
|
+
instance = CloudFormer::EC2::Instance.new('myinstance') do
|
68
|
+
# list
|
69
|
+
block_device_mappings(2) do |i|
|
70
|
+
device_name "/dev/sdf".tap { |s| i.times { s.succ! } }
|
71
|
+
# single
|
72
|
+
ebs do
|
73
|
+
volume_size 100
|
74
|
+
volume_type 'standard'
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
template.add_resource(instance)
|
79
|
+
|
80
|
+
expect(template.dump_json).to eq(
|
81
|
+
"AWSTemplateFormatVersion" => "2010-09-09",
|
82
|
+
"Resources" => {
|
83
|
+
"myinstance" => {
|
84
|
+
"Type" => "AWS::EC2::Instance",
|
85
|
+
"Properties" => {
|
86
|
+
"BlockDeviceMappings" => [
|
87
|
+
{
|
88
|
+
"DeviceName" => "/dev/sdf",
|
89
|
+
"Ebs" => {
|
90
|
+
"VolumeSize" => 100,
|
91
|
+
"VolumeType" => "standard",
|
92
|
+
},
|
93
|
+
},
|
94
|
+
{
|
95
|
+
"DeviceName" => "/dev/sdg",
|
96
|
+
"Ebs" => {
|
97
|
+
"VolumeSize" => 100,
|
98
|
+
"VolumeType" => "standard",
|
99
|
+
},
|
100
|
+
},
|
101
|
+
],
|
102
|
+
},
|
103
|
+
},
|
104
|
+
},
|
105
|
+
)
|
106
|
+
end
|
107
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloud_former
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aubrey Holland
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -244,6 +244,7 @@ files:
|
|
244
244
|
- lib/cloud_former/resources/sqs/queue_policy.rb
|
245
245
|
- lib/cloud_former/template.rb
|
246
246
|
- lib/cloud_former/version.rb
|
247
|
+
- spec/has_properties_and_attributes_spec.rb
|
247
248
|
- spec/metadata_spec.rb
|
248
249
|
- spec/output_spec.rb
|
249
250
|
- spec/parameter_spec.rb
|
@@ -281,6 +282,7 @@ signing_key:
|
|
281
282
|
specification_version: 4
|
282
283
|
summary: A Ruby DSL for creating CloudFormation templates
|
283
284
|
test_files:
|
285
|
+
- spec/has_properties_and_attributes_spec.rb
|
284
286
|
- spec/metadata_spec.rb
|
285
287
|
- spec/output_spec.rb
|
286
288
|
- spec/parameter_spec.rb
|