convection 0.4.0 → 0.4.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7f560ff0230cc8a78bdc3e59c57d2b5befbfe37
|
4
|
+
data.tar.gz: 54969c701ca627f77a22a38a67e70aa43e1c93a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1db320b7089911c0e28b80709348897131f11f4a15e3529e406c78d09760cb65d0aa8df505e98c1f2d84e707b3383311cc5c044198cc9f5ba25648beb5d3b01d
|
7
|
+
data.tar.gz: 11e1bce3c3781d8899f6ad2c5ac1a0acc6ba1ec3766160c0e1cc0c96f279330831b67121aab7e8173cf5ea55fae9f52ed3d1260be86aa17274a0410be0a9cd95
|
@@ -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.
|
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' =>
|
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.4.
|
4
|
+
version: 0.4.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
|
@@ -284,7 +286,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
284
286
|
version: '0'
|
285
287
|
requirements: []
|
286
288
|
rubyforge_project:
|
287
|
-
rubygems_version: 2.4.
|
289
|
+
rubygems_version: 2.4.5
|
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
|