cfndsl 1.0.5 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -36,7 +36,9 @@ describe 'cfndsl', type: :aruba do
36
36
  before(:each) { write_file('template.rb', template_content) }
37
37
 
38
38
  # The known working version is the embedded version
39
+ # rubocop:disable Lint/ConstantDefinitionInBlock
39
40
  WORKING_SPEC_VERSION = JSON.parse(File.read(CfnDsl::LOCAL_SPEC_FILE))['ResourceSpecificationVersion']
41
+ # rubocop:enable Lint/ConstantDefinitionInBlock
40
42
 
41
43
  context "cfndsl -u #{WORKING_SPEC_VERSION}" do
42
44
  it 'updates the specification file' do
@@ -40,10 +40,31 @@ describe CfnDsl::CloudFormationTemplate do
40
40
  expect(subject.validate).to equal(subject)
41
41
  end
42
42
 
43
+ it 'returns self if there are valid Fn::Sub references to other resources' do
44
+ tr = subject.Resource(:TestResource)
45
+ tr.Type('Custom-TestType')
46
+ tr.Property(:AProperty, tr.FnSub('prefix ${TestResource2}suffix'))
47
+
48
+ t2 = subject.Resource('TestResource2')
49
+ t2.Type('Custom-TestType')
50
+ expect(subject.validate).to equal(subject)
51
+ end
52
+
53
+ it 'returns self if there are valid Fn::Sub references to other resource attributes' do
54
+ tr = subject.Resource(:TestResource)
55
+ tr.Type('Custom-TestType')
56
+ tr.Property(:AProperty, tr.FnSub('prefix ${TestResource2.AnAttribute}suffix'))
57
+
58
+ t2 = subject.Resource('TestResource2')
59
+ t2.Type('Custom-TestType')
60
+ expect(subject.validate).to equal(subject)
61
+ end
62
+
43
63
  it 'returns self if there are valid DependsOn to other resources' do
44
64
  tr = subject.Resource(:TestResource)
45
65
  tr.Type('Custom-TestType')
46
66
  tr.DependsOn(:TestResource2)
67
+ tr.DependsOn(:TestResource2)
47
68
 
48
69
  t2 = subject.Resource('TestResource2')
49
70
  t2.Type('Custom-TestType')
@@ -119,6 +140,13 @@ describe CfnDsl::CloudFormationTemplate do
119
140
  expect { subject.validate }.to raise_error(CfnDsl::Error, /TestResource.*itself/i)
120
141
  end
121
142
 
143
+ it 'raises CfnDsl::Error if a resourcs references itself in Fn::Sub attribute expression' do
144
+ tr = subject.Resource(:TestResource)
145
+ tr.Type('Custom-TestType')
146
+ tr.Property(:AProperty, tr.FnSub('${TestResource.attr}'))
147
+ expect { subject.validate }.to raise_error(CfnDsl::Error, /TestResource.*itself/i)
148
+ end
149
+
122
150
  it 'raises CfnDsl::Error if there are cyclic DependsOn references' do
123
151
  tr = subject.Resource(:ResourceOne)
124
152
  tr.Type('Custom-TestType')
@@ -211,6 +239,12 @@ describe CfnDsl::CloudFormationTemplate do
211
239
  expect(subject.validate).to equal(subject)
212
240
  end
213
241
 
242
+ it 'returns self if there are valid Fn::Sub references to resource attributes' do
243
+ subject.Resource(:TestResource)
244
+ subject.Output('TestResourceOutput').Value(subject.FnSub('prefix ${TestResource.attr}suffix'))
245
+ expect(subject.validate).to equal(subject)
246
+ end
247
+
214
248
  it 'raises CfnDsl::Error if references a non existent condition' do
215
249
  subject.Output(:TestOutput).Condition('NoCondition')
216
250
  expect { subject.validate }.to raise_error(CfnDsl::Error, /TestOutput.*NoCondition/)
@@ -102,6 +102,13 @@ shared_examples 'an orchestration template' do
102
102
  expect(plural_value).to eq([{ foo: 'bar' }])
103
103
  end
104
104
 
105
+ it 'allows array returning function for otherwise array value when singular name == plural name' do
106
+ security_group = described_class.type_module.const_get('AWS_EC2_SecurityGroup').new
107
+ security_group.Property('SecurityGroupIngress', security_group.FnFindInMap('x', 'y', 'z'))
108
+ plural_value = security_group.instance_variable_get('@Properties')['SecurityGroupIngress'].value
109
+ expect(plural_value.to_json).to eql('{"Fn::FindInMap":["x","y","z"]}')
110
+ end
111
+
105
112
  it 'sets the type of each resource correctly' do
106
113
  ec2_instance = subject.EC2_Instance(:foo)
107
114
  expect(ec2_instance.instance_variable_get('@Type')).to eq('AWS::EC2::Instance')
@@ -27,9 +27,10 @@ RSpec.describe 'Type Definitions' do
27
27
  it "#{name} has all property types defined" do
28
28
  type = type['Properties'] if type.is_a?(Hash) && type.key?('Properties')
29
29
  type = type.first if type.is_a?(Array)
30
- if type.is_a?(String)
30
+ case type
31
+ when String
31
32
  expect(types).to have_key(type)
32
- elsif type.is_a?(Hash)
33
+ when Hash
33
34
  type.values.flatten.each { |t| expect(types).to have_key(t) }
34
35
  else
35
36
  raise "A defined type should only be of the form String, Array or Hash, got #{type.class}"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfndsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Jack
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2020-03-20 00:00:00.000000000 Z
14
+ date: 2021-01-03 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler
@@ -19,14 +19,14 @@ dependencies:
19
19
  requirements:
20
20
  - - "~>"
21
21
  - !ruby/object:Gem::Version
22
- version: '2.1'
22
+ version: '2.2'
23
23
  type: :development
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: '2.1'
29
+ version: '2.2'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: hana
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -70,6 +70,8 @@ files:
70
70
  - lib/cfndsl/aws/patches/000_sam.spec.json
71
71
  - lib/cfndsl/aws/patches/100_sam.spec_DeploymentPreference_patch.json
72
72
  - lib/cfndsl/aws/patches/200_Scrutinies_patch.json
73
+ - lib/cfndsl/aws/patches/500_BadTagsv13.0.0_patch.json
74
+ - lib/cfndsl/aws/patches/500_BadTagsv16.2.0_patch.json
73
75
  - lib/cfndsl/aws/patches/500_Cognito_IdentityPoolRoleAttachment_patches.json
74
76
  - lib/cfndsl/aws/patches/500_IoT1Click_patch_PlacementTemplate_DeviceTemplates.json
75
77
  - lib/cfndsl/aws/patches/500_NetworkAclEntry_patch.json
@@ -82,6 +84,7 @@ files:
82
84
  - lib/cfndsl/aws/patches/600_RefKinds_patch.json
83
85
  - lib/cfndsl/aws/patches/700_SAM_Serverless_Function_InlineCode_patch.json
84
86
  - lib/cfndsl/aws/patches/800_List_types_patch.json
87
+ - lib/cfndsl/aws/patches/900_SageMakerTags_patch.json
85
88
  - lib/cfndsl/aws/resource_specification.json
86
89
  - lib/cfndsl/aws/types.rb
87
90
  - lib/cfndsl/aws/types.yaml
@@ -183,15 +186,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
183
186
  requirements:
184
187
  - - "~>"
185
188
  - !ruby/object:Gem::Version
186
- version: '2.3'
189
+ version: '2.7'
187
190
  required_rubygems_version: !ruby/object:Gem::Requirement
188
191
  requirements:
189
192
  - - ">="
190
193
  - !ruby/object:Gem::Version
191
194
  version: '0'
192
195
  requirements: []
193
- rubyforge_project:
194
- rubygems_version: 2.7.7
196
+ rubygems_version: 3.0.8
195
197
  signing_key:
196
198
  specification_version: 4
197
199
  summary: AWS Cloudformation DSL