convection 0.3.2 → 0.3.3.pre.beta.1

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: 28794b0bf83508a07221ce39fb4618d474b4661b
4
- data.tar.gz: 2e5fff11023f29aeac41e943885b47cd7e0d7746
3
+ metadata.gz: 92bb70d18fb3687340fc65242ff82a60e85b8fd0
4
+ data.tar.gz: 8f337a4df378596d37ebac562f5f8934c55a8342
5
5
  SHA512:
6
- metadata.gz: 003097ab01fecbeb958fa111b850b5e8898c562a5fe3800229a3d528728b232805cb0ca77a76b1932bc6cb1b5bd4f71ca37a3bad973fe496e15ef9a0ea48efca
7
- data.tar.gz: 48256617657cc9ddb72e3b46c520ff5c6eedb4986355b1114c982a9af4d309eeada53d07ea6933f6edc6d0bcae7c0748dc9ea9433c15193d4c8794feb47b7680
6
+ metadata.gz: c75506899cc2c95d0f43c47d16a69d01860211ab7181120f5a986821815e7d6241b8a5e08629fa12d593272923b731408dd782e69b7627bbdb571bd7c8d19cd9
7
+ data.tar.gz: 0b7dc45590327bd36dc8468342dd146a58fb12ca024f4bcf316c0d0b649dcbf18ceefada272c86b90c3e971a961c4a85dd219225ca0aba65542a494343012a75
@@ -254,7 +254,7 @@ module Convection
254
254
  # template has any changes compared to the current template (in
255
255
  # CloudFormation).
256
256
  def resource_changes?
257
- ours = { 'Resources' => @template.resources.map(&:render) }
257
+ ours = { 'Resources' => @template.all_resources.map(&:render) }
258
258
  thiers = { 'Resources' => @current_template['Resources'] }
259
259
 
260
260
  ours.diff(thiers).any?
@@ -24,6 +24,12 @@ module Convection
24
24
  resources[rname] = resource
25
25
  end
26
26
  end
27
+
28
+ def attach_resource_collection(name, klass)
29
+ define_method(name) do |rname, &block|
30
+ resource_collections[rname] = klass.new(rname, self, &block)
31
+ end
32
+ end
27
33
  end
28
34
  end
29
35
 
@@ -187,6 +193,7 @@ module Convection
187
193
  attr_reader :parameters
188
194
  attr_reader :mappings
189
195
  attr_reader :conditions
196
+ attr_reader :resource_collections
190
197
  attr_reader :resources
191
198
  attr_reader :outputs
192
199
 
@@ -207,6 +214,7 @@ module Convection
207
214
  @mappings = Collection.new
208
215
  @conditions = Collection.new
209
216
  @resources = Collection.new
217
+ @resource_collections = Collection.new
210
218
  @outputs = Collection.new
211
219
  @metadata = Collection.new
212
220
  end
@@ -217,6 +225,11 @@ module Convection
217
225
 
218
226
  def execute
219
227
  instance_exec(&@definition)
228
+
229
+ resource_collections.each do |_, group|
230
+ group.run_definition
231
+ group.execute
232
+ end
220
233
  end
221
234
 
222
235
  def render(stack_ = nil)
@@ -231,12 +244,18 @@ module Convection
231
244
  'Parameters' => parameters.map(&:render),
232
245
  'Mappings' => mappings.map(&:render),
233
246
  'Conditions' => conditions.map(&:render),
234
- 'Resources' => resources.map(&:render),
247
+ 'Resources' => all_resources.map(&:render),
235
248
  'Outputs' => outputs.map(&:render),
236
249
  'Metadata' => metadata.map(&:render)
237
250
  }
238
251
  end
239
252
 
253
+ def all_resources
254
+ resource_collections.reduce(resources) do |result, (_name, resource_collection)|
255
+ result.merge(resource_collection.resources)
256
+ end
257
+ end
258
+
240
259
  def diff(other, stack_ = nil)
241
260
  render(stack_).diff(other).map { |diff| Diff.new(diff[0], *diff[1]) }
242
261
  end
@@ -353,5 +372,6 @@ require_relative 'template/condition'
353
372
  require_relative 'template/resource'
354
373
  require_relative 'template/resource_property'
355
374
  require_relative 'template/resource_attribute'
375
+ require_relative 'template/resource_collection'
356
376
  require_relative 'template/output'
357
377
  require_relative 'template/metadata'
@@ -0,0 +1,48 @@
1
+ require 'forwardable'
2
+ require_relative './resource'
3
+ require_relative '../mixin/conditional'
4
+
5
+ module Convection
6
+ module Model
7
+ class Template
8
+ # A collection of different {Convection::Model::Template::Resource}s.
9
+ class ResourceCollection
10
+ extend Forwardable
11
+ include DSL::Helpers
12
+ include DSL::Template::Resource
13
+ include Mixin::Conditional
14
+
15
+ attr_reader :name
16
+ attr_reader :parent
17
+ attr_reader :template
18
+
19
+ def_delegator :@template, :stack
20
+
21
+ class << self
22
+ def attach_to_dsl(dsl_name)
23
+ DSL::Template::Resource.attach_resource_collection(dsl_name, self)
24
+ end
25
+ end
26
+
27
+ def initialize(name, parent, &definition)
28
+ @definition = definition
29
+ @name = name
30
+ @parent = parent
31
+ @template = parent.template
32
+ end
33
+
34
+ # @note This method is in place to be overriden by subclasses.
35
+ def execute
36
+ end
37
+
38
+ def run_definition
39
+ instance_exec(&@definition) if @definition
40
+ end
41
+
42
+ def resources
43
+ @resources ||= Convection::Model::Collection.new
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ class Convection::Model::Template
4
+ describe ResourceCollection do
5
+ class WebService < Convection::Model::Template::ResourceCollection
6
+ attach_to_dsl(:web_service)
7
+
8
+ attribute :use_elastic_load_balancing
9
+
10
+ def execute
11
+ web_service = self # Expose this instance to nested template methods.
12
+
13
+ ec2_instance "#{name}WebService"
14
+
15
+ elb "#{name}LoadBalancer" do
16
+ tag 'Description', "Load balancer for the #{web_service.name} web service."
17
+ end if use_elastic_load_balancing
18
+ end
19
+ end
20
+
21
+ let(:use_elb_value) { nil }
22
+ let(:template) do
23
+ outer_scope = self
24
+ Convection.template do
25
+ description 'ResourceCollection Test Template'
26
+
27
+ # A lone resource for testing merging of resources and nested resources.
28
+ ec2_instance 'LoneResource1'
29
+
30
+ web_service 'ExampleDotOrg' do
31
+ use_elastic_load_balancing outer_scope.use_elb_value
32
+ end
33
+ end
34
+ end
35
+
36
+ subject do
37
+ template_json
38
+ .fetch('Resources')
39
+ end
40
+
41
+ context 'when the use_elastic_load_balancing attribute is set' do
42
+ let(:use_elb_value) { true }
43
+
44
+ it { is_expected.to have_key('LoneResource1') }
45
+ it { is_expected.to have_key('ExampleDotOrgWebService') }
46
+ it { is_expected.to have_key('ExampleDotOrgLoadBalancer') }
47
+ end
48
+
49
+ context 'when the use_elastic_load_balancing attribute is not set' do
50
+ let(:use_elb_value) { false }
51
+
52
+ it { is_expected.to have_key('LoneResource1') }
53
+ it { is_expected.to have_key('ExampleDotOrgWebService') }
54
+ it { is_expected.to_not have_key('ExampleDotOrgLoadBalancer') }
55
+ end
56
+
57
+ private
58
+
59
+ def template_json
60
+ JSON.parse(template.to_json)
61
+ end
62
+ end
63
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: convection
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3.pre.beta.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Manero
@@ -203,6 +203,7 @@ files:
203
203
  - lib/convection/model/template/resource/aws_sqs_queue_policy.rb
204
204
  - lib/convection/model/template/resource_attribute.rb
205
205
  - lib/convection/model/template/resource_attribute/update_policy.rb
206
+ - lib/convection/model/template/resource_collection.rb
206
207
  - lib/convection/model/template/resource_property.rb
207
208
  - lib/convection/model/template/resource_property/aws_cloudfront_cachebehavior.rb
208
209
  - lib/convection/model/template/resource_property/aws_cloudfront_customerrorresponse.rb
@@ -252,6 +253,7 @@ files:
252
253
  - spec/convection/model/template/resource/rds_security_groups_spec.rb
253
254
  - spec/convection/model/template/resource/vpc_endpoints_spec.rb
254
255
  - spec/convection/model/template/resource_attribute/update_policies_spec.rb
256
+ - spec/convection/model/template/resource_collection_spec.rb
255
257
  - spec/convection/model/template/template_spec.rb
256
258
  - spec/convection/model/template/validate_bytesize_spec.rb
257
259
  - spec/convection/model/template/validate_description_spec.rb
@@ -279,12 +281,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
279
281
  version: '0'
280
282
  required_rubygems_version: !ruby/object:Gem::Requirement
281
283
  requirements:
282
- - - ">="
284
+ - - ">"
283
285
  - !ruby/object:Gem::Version
284
- version: '0'
286
+ version: 1.3.1
285
287
  requirements: []
286
288
  rubyforge_project:
287
- rubygems_version: 2.4.5
289
+ rubygems_version: 2.4.8
288
290
  signing_key:
289
291
  specification_version: 4
290
292
  summary: A fully generic, modular DSL for AWS CloudFormation
@@ -315,6 +317,7 @@ test_files:
315
317
  - spec/convection/model/template/resource/rds_security_groups_spec.rb
316
318
  - spec/convection/model/template/resource/vpc_endpoints_spec.rb
317
319
  - spec/convection/model/template/resource_attribute/update_policies_spec.rb
320
+ - spec/convection/model/template/resource_collection_spec.rb
318
321
  - spec/convection/model/template/template_spec.rb
319
322
  - spec/convection/model/template/validate_bytesize_spec.rb
320
323
  - spec/convection/model/template/validate_description_spec.rb