cfndsl 1.0.3 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,7 +14,7 @@ module Cfnlego
14
14
  end
15
15
 
16
16
  def render
17
- erb = ERB.new(File.read(TEMPLATE), nil, '-')
17
+ erb = ERB.new(File.read(TEMPLATE), trim_mode: '-')
18
18
  erb.result(binding)
19
19
  end
20
20
  end
@@ -87,7 +87,7 @@ module CfnDsl
87
87
  def FnSub(string, substitutions = nil)
88
88
  raise ArgumentError, 'The first argument passed to Fn::Sub must be a string' unless string.is_a? String
89
89
 
90
- refs = string.scan(FN_SUB_SCANNER).map(&:first)
90
+ refs = string.scan(FN_SUB_SCANNER).map(&:first).map { |r| r.split('.', 2).first }
91
91
 
92
92
  if substitutions
93
93
  raise ArgumentError, 'The second argument passed to Fn::Sub must be a Hash' unless substitutions.is_a? Hash
@@ -169,7 +169,7 @@ module CfnDsl
169
169
  def check_names
170
170
  return if instance_variable_get('@Resources').nil?
171
171
 
172
- instance_variable_get('@Resources').keys.each do |name|
172
+ instance_variable_get('@Resources').each_key do |name|
173
173
  next unless name !~ /\A\p{Alnum}+\z/
174
174
 
175
175
  warn "Resource name: #{name} is invalid"
@@ -22,7 +22,7 @@ module CfnDsl
22
22
  # Handles the overall template object
23
23
  # rubocop:disable Metrics/ClassLength
24
24
  class OrchestrationTemplate < JSONable
25
- dsl_attr_setter :AWSTemplateFormatVersion, :Description, :Metadata, :Transform
25
+ dsl_attr_setter :AWSTemplateFormatVersion, :Description, :Metadata, :Transform, :Hooks
26
26
  dsl_content_object :Condition, :Parameter, :Output, :Resource, :Mapping, :Rule
27
27
 
28
28
  GLOBAL_REFS = {
@@ -135,7 +135,8 @@ module CfnDsl
135
135
  # @param [Hash] yaml_opts, other options to pass to YAML generator
136
136
  def yaml(name:, files:, pathmap:, extras: [], **yaml_opts)
137
137
  generate_model_tasks(name: name, files: files, pathmap: pathmap, extras: extras) do |model, f|
138
- YAML.dump(model, f, **yaml_opts)
138
+ simple_model = JSON.parse(model.to_json) # convert model to a simple ruby object to avoid yaml tags
139
+ YAML.dump(simple_model, f, **yaml_opts)
139
140
  end
140
141
  self
141
142
  end
@@ -189,7 +190,7 @@ module CfnDsl
189
190
  files.each do |source|
190
191
  matched_extras = build_extras_filelist(source, extras)
191
192
 
192
- file source.pathmap(pathmap) => [source, :load_spec_types, matched_extras] do |task|
193
+ file source.pathmap(pathmap) => [source, :load_spec_types, *matched_extras] do |task|
193
194
  eval_extras = matched_extras.map { |e| [:yaml, e] } # eval treats yaml and json same
194
195
  puts "Generating Cloudformation for #{source} to #{task.name}"
195
196
  model = CfnDsl.eval_file_with_extras(source, eval_extras, verbose)
@@ -5,7 +5,7 @@ require_relative 'jsonable'
5
5
  module CfnDsl
6
6
  # Handles Resource objects
7
7
  class ResourceDefinition < JSONable
8
- dsl_attr_setter :Type, :DependsOn, :DeletionPolicy, :Condition, :Metadata
8
+ dsl_attr_setter :Type, :DependsOn, :UpdateReplacePolicy, :DeletionPolicy, :Condition, :Metadata
9
9
  dsl_content_object :Property, :UpdatePolicy, :CreationPolicy
10
10
 
11
11
  def add_tag(name, value, propagate = nil)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CfnDsl
4
- VERSION = '1.0.3'
4
+ VERSION = '1.1.1'
5
5
  end
@@ -0,0 +1 @@
1
+ description: 5 machine cluster
@@ -1,2 +1 @@
1
- description: 5 machine cluster
2
1
  machines: 5
@@ -40,6 +40,26 @@ 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')
@@ -119,6 +139,13 @@ describe CfnDsl::CloudFormationTemplate do
119
139
  expect { subject.validate }.to raise_error(CfnDsl::Error, /TestResource.*itself/i)
120
140
  end
121
141
 
142
+ it 'raises CfnDsl::Error if a resourcs references itself in Fn::Sub attribute expression' do
143
+ tr = subject.Resource(:TestResource)
144
+ tr.Type('Custom-TestType')
145
+ tr.Property(:AProperty, tr.FnSub('${TestResource.attr}'))
146
+ expect { subject.validate }.to raise_error(CfnDsl::Error, /TestResource.*itself/i)
147
+ end
148
+
122
149
  it 'raises CfnDsl::Error if there are cyclic DependsOn references' do
123
150
  tr = subject.Resource(:ResourceOne)
124
151
  tr.Type('Custom-TestType')
@@ -211,6 +238,12 @@ describe CfnDsl::CloudFormationTemplate do
211
238
  expect(subject.validate).to equal(subject)
212
239
  end
213
240
 
241
+ it 'returns self if there are valid Fn::Sub references to resource attributes' do
242
+ subject.Resource(:TestResource)
243
+ subject.Output('TestResourceOutput').Value(subject.FnSub('prefix ${TestResource.attr}suffix'))
244
+ expect(subject.validate).to equal(subject)
245
+ end
246
+
214
247
  it 'raises CfnDsl::Error if references a non existent condition' do
215
248
  subject.Output(:TestOutput).Condition('NoCondition')
216
249
  expect { subject.validate }.to raise_error(CfnDsl::Error, /TestOutput.*NoCondition/)
@@ -12,6 +12,7 @@ describe Cfnlego do
12
12
  output << '# http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-eip.html#cfn-ec2-eip-domain'
13
13
  output << "\n InstanceId String # http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-eip.html#cfn-ec2-eip-instanceid"
14
14
  output << "\n PublicIpv4Pool String # http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-eip.html#cfn-ec2-eip-publicipv4pool"
15
+ output << "\n Tags [List] # http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-eip.html#cfn-ec2-eip-tags"
15
16
  output << "\n end\nend\n"
16
17
  expect(template).to eq output
17
18
  end
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.3
4
+ version: 1.1.1
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-12 00:00:00.000000000 Z
14
+ date: 2020-06-02 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler
@@ -70,6 +70,7 @@ 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
73
74
  - lib/cfndsl/aws/patches/500_Cognito_IdentityPoolRoleAttachment_patches.json
74
75
  - lib/cfndsl/aws/patches/500_IoT1Click_patch_PlacementTemplate_DeviceTemplates.json
75
76
  - lib/cfndsl/aws/patches/500_NetworkAclEntry_patch.json
@@ -128,6 +129,7 @@ files:
128
129
  - sample/import.rb
129
130
  - sample/lambda.rb
130
131
  - sample/s3.rb
132
+ - sample/t1-extra.yaml
131
133
  - sample/t1.rb
132
134
  - sample/t1.yaml
133
135
  - sample/vpc_example.rb
@@ -182,7 +184,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
182
184
  requirements:
183
185
  - - "~>"
184
186
  - !ruby/object:Gem::Version
185
- version: '2.3'
187
+ version: '2.4'
186
188
  required_rubygems_version: !ruby/object:Gem::Requirement
187
189
  requirements:
188
190
  - - ">="