rubycfn 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: d733dda0a2fd9505dc4e84d6d65670f3acbe1322
4
- data.tar.gz: 782fc35dc9375763e592671ab952fa18679f80a6
3
+ metadata.gz: 77a1afcae7e2469088c77ddfdacc834ceb5dcedb
4
+ data.tar.gz: d4fbf293e830231a08448ae01c85930708a0da66
5
5
  SHA512:
6
- metadata.gz: 68087c6444b29e2d5f26871dcdf8e805b3996481066c93f4a444cbe161d85d8372caccf980ad6b01496e360fc0d69fa9f5266c3ba22a6efa6bdff5809c3ad17b
7
- data.tar.gz: 2d3780fb60ca99005a14248dced1e4f9041fda32efd2541a4ab921f14116e183c07bd0ef0cd346b561c697d2851f7bbd12594fa9b857c645b6d9e313c6e21ec6
6
+ metadata.gz: dff45cf27402459563b2148092d9c4328e61ae189cbeffcbe33330b852fe70c580cf32369b2c2b03b96c7aa4f6f22cd1486011a40573afe330c7590f6a4927d5
7
+ data.tar.gz: 095172e5e1aec34e99b439c3d253e359c29923171bd4473fddb913d04fafea3c8b865c40512597b2a11fd2984563fd4975fd98dec18f3cbc256e4563ac7a3a34
data/CHANGELOG.md CHANGED
@@ -2,7 +2,12 @@
2
2
  All notable changes to Rubycfn will be documented in this file.
3
3
  This project uses [Semantic Versioning](http://semver.org/).
4
4
 
5
- ## 0.4.1 (Next Release)
5
+ ## 0.4.2 (Next Release)
6
+
7
+ ## 0.4.1
8
+
9
+ * Fixed bug with DependsOn not being rendered correctly on multiple instances of resource -- [@dennisvink][@dennisvink]
10
+ * Added specs for Ref and Fn::GetAtt transformations with strings and symbols -- [@dennisvink][@dennisvink]
6
11
 
7
12
  ## 0.4.0
8
13
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubycfn (0.4.0)
4
+ rubycfn (0.4.1)
5
5
  activesupport (~> 5.1.5)
6
6
  dotenv (~> 2.4.0)
7
7
  json (~> 2.1.0)
data/README.md CHANGED
@@ -61,7 +61,7 @@ __________ ____ __________________.___._________ _____________________
61
61
  | _/ | /| | _// | |/ \ \/ | __) | | _/
62
62
  | | \ | / | | \\____ |\ \____| \ | | \
63
63
  |____|_ /______/ |______ // ______| \______ /\___ / |______ /
64
- \/ \/ \/ \/ \/ \/ [v0.4.0]
64
+ \/ \/ \/ \/ \/ \/ [v0.4.1]
65
65
  Project name? example
66
66
  Account ID? 1234567890
67
67
  Select region EU (Frankfurt)
@@ -1,4 +1,4 @@
1
1
  # Rubycfn version
2
2
  module Rubycfn
3
- VERSION = "0.4.0".freeze
3
+ VERSION = "0.4.1".freeze
4
4
  end
data/lib/rubycfn.rb CHANGED
@@ -407,21 +407,12 @@ module Rubycfn
407
407
  # If the argument is a string, create an array out of it with a single element
408
408
  arguments[:depends_on] = arguments[:depends_on].class == Array && arguments[:depends_on] || [arguments[:depends_on]]
409
409
 
410
- # `r.depends_on` is used to amend depends_on with resources with dynamic names
411
- # Here we add them to arguments[:depends_on]
412
- to_amend = TOPLEVEL_BINDING.eval("@depends_on")
413
- unless to_amend.nil?
414
- to_amend = to_amend.class == String && [to_amend] || to_amend
415
- to_amend.each do |amend|
416
- arguments[:depends_on].push(amend)
417
- end
418
- end
419
- TOPLEVEL_BINDING.eval("@depends_on = []")
420
-
421
410
  # Finally, we render the DependsOn array
422
411
  arguments[:depends_on].map! { |resource| resource.class == String && resource.to_s || resource.to_s.split("_").map(&:capitalize).join }
423
412
  end
424
413
 
414
+ arguments[:depends_on] ||= []
415
+ rendered_depends_on = TOPLEVEL_BINDING.eval("@depends_on").nil? && arguments[:depends_on] || arguments[:depends_on] + TOPLEVEL_BINDING.eval("@depends_on")
425
416
  res = {
426
417
  "#{name.to_s}#{i.zero? ? "" : resource_postpend}": {
427
418
  Properties: TOPLEVEL_BINDING.eval("@properties"),
@@ -430,12 +421,11 @@ module Rubycfn
430
421
  UpdatePolicy: arguments[:update_policy],
431
422
  UpdateReplacePolicy: arguments[:update_replace_policy],
432
423
  Metadata: arguments[:metadata],
433
- DependsOn: arguments[:depends_on],
424
+ DependsOn: rendered_depends_on,
434
425
  DeletionPolicy: arguments[:deletion_policy],
435
426
  CreationPolicy: arguments[:creation_policy]
436
427
  }
437
428
  }
438
- arguments[:depends_on] = []
439
429
  TOPLEVEL_BINDING.eval("@aws_resources = @aws_resources.deep_merge(#{res})")
440
430
  end
441
431
  TOPLEVEL_BINDING.eval("@depends_on = []")
@@ -20,9 +20,13 @@ describe Rubycfn do
20
20
  "WillReplace": true
21
21
  }
22
22
  },
23
- amount: 2 do |r|
24
- r.depends_on [ "barFoo", :bar_foo ]
23
+ amount: 2 do |r, index|
24
+ r.depends_on [ "barFoo", :bar_foo ] unless index.positive?
25
25
  r.property(:name) { "RSpec" }
26
+ r.property(:security_group_id) { :rspec_security_group.ref }
27
+ r.property(:some_other_ref) { "rSpecSecurityGroup".ref }
28
+ r.property(:some_arn) { :rspec_resource.ref(:arn) }
29
+ r.property(:some_other_arn) { :rspec_resource.ref("FooBar") }
26
30
  end
27
31
  end
28
32
  end
@@ -54,6 +58,8 @@ describe Rubycfn do
54
58
  subject { resources }
55
59
 
56
60
  it { should have_key "RspecResourceName" }
61
+ it { should have_key "RspecResourceName2" }
62
+ it { should_not have_key "RspecResourceName3" }
57
63
 
58
64
  context "has resource type" do
59
65
  let(:resource) { resources["RspecResourceName"] }
@@ -71,6 +77,45 @@ describe Rubycfn do
71
77
  it { should eq ["FooBar", "fooBar", "barFoo", "BarFoo"] }
72
78
  end
73
79
 
80
+ context "has correct properties" do
81
+ let(:properties) { resource["Properties"] }
82
+ subject { properties }
83
+
84
+ it { should have_key "Name" }
85
+ it { should have_key "SecurityGroupId" }
86
+ it { should have_key "SomeOtherRef" }
87
+ it { should have_key "SomeArn" }
88
+ it { should have_key "SomeOtherArn" }
89
+
90
+ context "ref symbol is rendered correctly" do
91
+ let(:ref_symbol) { properties["SecurityGroupId"] }
92
+ subject { ref_symbol }
93
+
94
+ it { should eq JSON.parse({ Ref: "RspecSecurityGroup" }.to_json) }
95
+ end
96
+
97
+ context "ref string is rendered correctly" do
98
+ let(:ref_string) { properties["SomeOtherRef"] }
99
+ subject { ref_string }
100
+
101
+ it { should eq JSON.parse({ Ref: "rSpecSecurityGroup" }.to_json) }
102
+ end
103
+
104
+ context "Fn:GetAtt with symbol is rendered correctly" do
105
+ let(:fngetatt_symbol) { properties["SomeArn"] }
106
+ subject { fngetatt_symbol }
107
+
108
+ it { should eq JSON.parse({ "Fn::GetAtt": ["RspecResource", "Arn"] }.to_json) }
109
+ end
110
+
111
+ context "Fn:GetAtt with string is rendered correctly" do
112
+ let(:fngetatt_string) { properties["SomeOtherArn"] }
113
+ subject { fngetatt_string }
114
+
115
+ it { should eq JSON.parse({ "Fn::GetAtt": ["RspecResource", "FooBar"] }.to_json) }
116
+ end
117
+ end
118
+
74
119
  context "resource type is correct" do
75
120
  let(:type) { resource["Type"] }
76
121
  subject { type }
@@ -89,7 +134,23 @@ describe Rubycfn do
89
134
  let(:update_policy) { resource["UpdatePolicy"] }
90
135
  subject { update_policy }
91
136
 
92
- it { should include("AutoScalingReplacingUpdate" => { "WillReplace" => true })}
137
+ it { should eq JSON.parse({ AutoScalingReplacingUpdate: { WillReplace: true }}.to_json) }
138
+ end
139
+ end
140
+ context "second resource does not have depends_on" do
141
+ let(:resource) { resources["RspecResourceName2"] }
142
+ subject { resource }
143
+
144
+ it { should have_key "DependsOn" }
145
+ it { should have_key "Type" }
146
+ it { should have_key "Properties" }
147
+ it { should have_key "UpdatePolicy"}
148
+
149
+ context "second resource renders only the initial depends_on resources" do
150
+ let(:depends_on) { resource["DependsOn"] }
151
+ subject { depends_on }
152
+
153
+ it { should eq ["FooBar", "fooBar"] }
93
154
  end
94
155
  end
95
156
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubycfn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dennis Vink
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-18 00:00:00.000000000 Z
11
+ date: 2019-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: neatjson