cfn2dsl 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/bin/cfn2dsl +1 -1
- data/lib/cfn2dsl.rb +14 -0
- data/lib/cfn_parser.rb +16 -16
- data/lib/cfndsl.erb +62 -42
- data/lib/cloudformation.rb +21 -15
- data/lib/condition.rb +1 -1
- data/lib/error.rb +11 -0
- data/lib/intrinsic_function.rb +32 -19
- data/lib/mapping.rb +1 -1
- data/lib/metadata.rb +1 -1
- data/lib/output.rb +5 -5
- data/lib/parameter.rb +2 -2
- data/lib/resource.rb +9 -9
- data/lib/rules.rb +1 -1
- data/lib/version.rb +1 -1
- metadata +10 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 362a368962d8e432205733286191423e04b5db0235647d243985153bed960b63
|
4
|
+
data.tar.gz: 26b99c51a9da1f59b26f3b06d3358c94cc19bc68cc5d0fb20078808cfcc44d77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8048e157208a924a3eae68415d96bf8c650a9484cefcea4d7d829c455cc35a0cf2c6fadb47e79cdbf8c195b92d41061ba4647f51c393bc5c0a2824819682ff4b
|
7
|
+
data.tar.gz: 2cba5277344c9e986890c1abe1ab434e989359389cc8dbb1357ead8f48591052bf79fb442f97d423e28f00b891ba7625074506210c7bd042828a212b37ca542d
|
data/bin/cfn2dsl
CHANGED
data/lib/cfn2dsl.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
2
|
|
3
3
|
require 'json'
|
4
|
+
require 'yaml'
|
4
5
|
require 'optparse'
|
5
6
|
require 'ap'
|
6
7
|
|
@@ -16,6 +17,7 @@ require 'render'
|
|
16
17
|
require 'version'
|
17
18
|
require 'rules'
|
18
19
|
require 'metadata'
|
20
|
+
require 'error'
|
19
21
|
|
20
22
|
AwesomePrint.defaults = {
|
21
23
|
:indent => -2,
|
@@ -24,3 +26,15 @@ AwesomePrint.defaults = {
|
|
24
26
|
:plain => true
|
25
27
|
}
|
26
28
|
|
29
|
+
YAML.add_domain_type('', 'Ref') { |type, val| { 'Ref' => val } }
|
30
|
+
|
31
|
+
YAML.add_domain_type('', 'GetAtt') do |type, val|
|
32
|
+
if val.is_a? String
|
33
|
+
val = val.split('.')
|
34
|
+
end
|
35
|
+
{ 'Fn::GetAtt' => val }
|
36
|
+
end
|
37
|
+
|
38
|
+
%w(Join Base64 Sub Cidr Split Select ImportValue GetAZs FindInMap And Or If Not).each do |function_name|
|
39
|
+
YAML.add_domain_type('', function_name) { |type, val| { "Fn::#{function_name}" => val } }
|
40
|
+
end
|
data/lib/cfn_parser.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module CfnParser
|
2
2
|
|
3
|
-
def
|
4
|
-
send(element_type(
|
3
|
+
def parse_cfn(cfn_hash)
|
4
|
+
send(element_type(cfn_hash).to_s.snake_case, cfn_hash)
|
5
5
|
end
|
6
6
|
|
7
7
|
def intrinsic_function?(obj)
|
@@ -10,30 +10,30 @@ module CfnParser
|
|
10
10
|
(obj.keys.first =~ /^Fn::/ or obj.keys.first == "Ref")
|
11
11
|
end
|
12
12
|
|
13
|
-
def array(
|
14
|
-
return
|
13
|
+
def array(cfn_hash)
|
14
|
+
return cfn_hash.map { |a| parse_cfn(a) }
|
15
15
|
end
|
16
16
|
|
17
|
-
def intrinsic_function(
|
18
|
-
fn_name =
|
19
|
-
values =
|
20
|
-
parameters =
|
17
|
+
def intrinsic_function(cfn_hash)
|
18
|
+
fn_name = cfn_hash.keys.first
|
19
|
+
values = cfn_hash[fn_name]
|
20
|
+
parameters = parse_cfn(values)
|
21
21
|
return IntrinsicFunction.new(fn_name, parameters)
|
22
22
|
end
|
23
23
|
|
24
|
-
def hash(
|
25
|
-
return
|
24
|
+
def hash(cfn_hash)
|
25
|
+
return cfn_hash.merge(cfn_hash) { |k, v| parse_cfn(v) }
|
26
26
|
end
|
27
27
|
|
28
|
-
def primitive(
|
29
|
-
|
28
|
+
def primitive(cfn_hash)
|
29
|
+
cfn_hash
|
30
30
|
end
|
31
31
|
|
32
32
|
private
|
33
|
-
def element_type(
|
34
|
-
return :Array if
|
35
|
-
return :IntrinsicFunction if intrinsic_function?(
|
36
|
-
return :Hash if
|
33
|
+
def element_type(cfn_hash)
|
34
|
+
return :Array if cfn_hash.instance_of?(Array)
|
35
|
+
return :IntrinsicFunction if intrinsic_function?(cfn_hash)
|
36
|
+
return :Hash if cfn_hash.instance_of?(Hash)
|
37
37
|
return :Primitive
|
38
38
|
end
|
39
39
|
end
|
data/lib/cfndsl.erb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
CloudFormation do
|
2
3
|
<% if @cfn.description %>
|
3
|
-
Description
|
4
|
+
Description '<%= @cfn.description %>'
|
4
5
|
<% end %>
|
5
6
|
<% if @cfn.aws_template_format_version %>
|
6
|
-
AWSTemplateFormatVersion
|
7
|
+
AWSTemplateFormatVersion '<%= @cfn.aws_template_format_version %>'
|
7
8
|
<% end %>
|
8
9
|
<% # Parameters %>
|
9
10
|
<%
|
@@ -11,44 +12,48 @@ CloudFormation do
|
|
11
12
|
@cfn.parameters.each do |param|
|
12
13
|
%>
|
13
14
|
|
14
|
-
Parameter(<%= param.name
|
15
|
+
Parameter('<%= param.name %>') do
|
15
16
|
<% if param.description %>
|
16
|
-
Description
|
17
|
+
Description '<%= param.description %>'
|
17
18
|
<% end %>
|
18
19
|
<% if param.type %>
|
19
|
-
Type
|
20
|
+
Type '<%= param.type %>'
|
20
21
|
<% end %>
|
21
22
|
<% if param.default
|
22
23
|
default_value = param.default
|
23
24
|
if param.default.respond_to? :dump
|
24
|
-
default_value = param.default
|
25
|
+
default_value = '\'' + param.default + '\''
|
25
26
|
end
|
26
27
|
%>
|
27
|
-
Default
|
28
|
+
Default <%= default_value %>
|
28
29
|
<% end %>
|
29
30
|
<% if param.allowed_values %>
|
30
|
-
|
31
|
+
<% if param.allowed_values.kind_of?(Array) %>
|
32
|
+
AllowedValues <%= param.allowed_values.ai.gsub('"', '\'').gsub(' ', ' ').gsub(/^\]$/, ' ]').gsub(/^\}$/, ' }') %>
|
33
|
+
<% else %>
|
34
|
+
AllowedValues '<%= param.allowed_values.ai.gsub('"', '\'') %>'
|
35
|
+
<% end %>
|
31
36
|
<% end %>
|
32
37
|
<% if param.allowed_pattern %>
|
33
|
-
AllowedPattern
|
38
|
+
AllowedPattern '<%= param.allowed_pattern %>'
|
34
39
|
<% end %>
|
35
40
|
<% if param.no_echo %>
|
36
|
-
NoEcho
|
41
|
+
NoEcho <%= param.no_echo %>
|
37
42
|
<% end %>
|
38
43
|
<% if param.max_length %>
|
39
|
-
MaxLength
|
44
|
+
MaxLength <%= param.max_length.to_i %>
|
40
45
|
<% end %>
|
41
46
|
<% if param.min_length %>
|
42
|
-
MinLength
|
47
|
+
MinLength <%= param.min_length.to_i %>
|
43
48
|
<% end %>
|
44
49
|
<% if param.max_value %>
|
45
|
-
MaxValue
|
50
|
+
MaxValue <%= param.max_value %>
|
46
51
|
<% end %>
|
47
52
|
<% if param.min_value %>
|
48
|
-
MinValue
|
53
|
+
MinValue <%= param.min_value %>
|
49
54
|
<% end %>
|
50
55
|
<% if param.constraint_description %>
|
51
|
-
ConstraintDescription
|
56
|
+
ConstraintDescription '<%= param.constraint_description %>'
|
52
57
|
<% end %>
|
53
58
|
end
|
54
59
|
<%
|
@@ -61,7 +66,7 @@ CloudFormation do
|
|
61
66
|
@cfn.mappings.each do |map|
|
62
67
|
%>
|
63
68
|
|
64
|
-
Mapping
|
69
|
+
Mapping '<%= map.name %>' '<%= map.values.ai.gsub('"', '\'') %>'
|
65
70
|
<%
|
66
71
|
end
|
67
72
|
end
|
@@ -72,7 +77,7 @@ CloudFormation do
|
|
72
77
|
@cfn.conditions.each do |cond|
|
73
78
|
%>
|
74
79
|
|
75
|
-
Condition(<%= cond.name
|
80
|
+
Condition('<%= cond.name %>', <%= cond.evaluations.ai.gsub('"', '\'').gsub(' ', ' ').gsub(/^\]/, ' ]').gsub(/^\)/, ' )') %>)
|
76
81
|
<%
|
77
82
|
end
|
78
83
|
end
|
@@ -81,19 +86,23 @@ CloudFormation do
|
|
81
86
|
<%
|
82
87
|
@cfn.resources.each do |res|
|
83
88
|
%>
|
84
|
-
|
85
|
-
|
86
|
-
|
89
|
+
<%
|
90
|
+
resname = res.name
|
91
|
+
restype = res.type
|
92
|
+
restype = restype.split('::').delete_if{|i|i=='AWS'}
|
93
|
+
restype = restype.join('::').gsub('::', '_')
|
94
|
+
%>
|
95
|
+
<%= restype %>('<%= resname %>') do
|
87
96
|
<%
|
88
97
|
if res.creation_policy
|
89
98
|
res.creation_policy.each_pair do |name, value|
|
90
99
|
if value.instance_of? String
|
91
|
-
value = value
|
100
|
+
value = '\'' + value + '\''
|
92
101
|
else
|
93
|
-
value = value.ai
|
102
|
+
value = value.ai.gsub('"', '\'')
|
94
103
|
end
|
95
104
|
%>
|
96
|
-
CreationPolicy(<%= name
|
105
|
+
CreationPolicy('<%= name %>', <%= value %>)
|
97
106
|
<%
|
98
107
|
end
|
99
108
|
end
|
@@ -101,14 +110,14 @@ CloudFormation do
|
|
101
110
|
<%
|
102
111
|
if res.deletion_policy
|
103
112
|
%>
|
104
|
-
DeletionPolicy
|
113
|
+
DeletionPolicy '<%= res.deletion_policy %>)'
|
105
114
|
<%
|
106
115
|
end
|
107
116
|
%>
|
108
117
|
<%
|
109
118
|
if res.condition
|
110
119
|
%>
|
111
|
-
Condition
|
120
|
+
Condition '<%= res.condition %>'
|
112
121
|
<%
|
113
122
|
end
|
114
123
|
%>
|
@@ -116,12 +125,12 @@ CloudFormation do
|
|
116
125
|
if res.update_policy
|
117
126
|
res.update_policy.each_pair do |name, value|
|
118
127
|
if value.instance_of? String
|
119
|
-
value = value
|
128
|
+
value = "'#{value}'"
|
120
129
|
else
|
121
|
-
value = value.ai
|
130
|
+
value = value.ai.gsub('"', '\'').gsub('{', '').gsub('}', '').chop
|
122
131
|
end
|
123
132
|
%>
|
124
|
-
UpdatePolicy(<%= name
|
133
|
+
UpdatePolicy('<%= name %>',<%= value %>)
|
125
134
|
<%
|
126
135
|
end
|
127
136
|
end
|
@@ -130,12 +139,12 @@ CloudFormation do
|
|
130
139
|
if res.metadata
|
131
140
|
res.metadata.each_pair do |name, value|
|
132
141
|
if value.instance_of? String
|
133
|
-
value = value
|
142
|
+
value = value
|
134
143
|
else
|
135
|
-
value = value.ai
|
144
|
+
value = value.ai.gsub('"', '\'')
|
136
145
|
end
|
137
146
|
%>
|
138
|
-
Metadata
|
147
|
+
Metadata '<%= name %>' '<%= value %>'
|
139
148
|
<%
|
140
149
|
end
|
141
150
|
end
|
@@ -143,9 +152,9 @@ CloudFormation do
|
|
143
152
|
<%
|
144
153
|
if res.depends_on
|
145
154
|
if res.depends_on.instance_of? String
|
146
|
-
value = res.depends_on
|
155
|
+
value = '\'' + res.depends_on + '\''
|
147
156
|
else
|
148
|
-
value = res.depends_on.ai
|
157
|
+
value = res.depends_on.ai.gsub('"', '\'')
|
149
158
|
end
|
150
159
|
%>
|
151
160
|
DependsOn(<%= value %>)
|
@@ -155,14 +164,25 @@ CloudFormation do
|
|
155
164
|
<%
|
156
165
|
if res.properties
|
157
166
|
res.properties.each_pair do |name, value|
|
167
|
+
is_value_string = true
|
158
168
|
if value.instance_of? String
|
159
|
-
value = value
|
169
|
+
value = '\'' + value + '\''
|
160
170
|
else
|
161
|
-
|
171
|
+
is_value_string = false
|
172
|
+
value = value.ai.gsub('"', '\'')
|
173
|
+
.gsub(' ', ' ')
|
174
|
+
.gsub(/^\]$/, ' ]')
|
175
|
+
.gsub(/^\}$/, ' }')
|
176
|
+
.gsub(/[ ]+=>/, ' =>')
|
162
177
|
end
|
178
|
+
|
179
|
+
if is_value_string
|
163
180
|
%>
|
164
|
-
|
181
|
+
<%= name %> <%= value %>
|
182
|
+
<% else %>
|
183
|
+
<%= name %>(<%= value %>)
|
165
184
|
<%
|
185
|
+
end
|
166
186
|
end
|
167
187
|
end
|
168
188
|
%>
|
@@ -176,30 +196,30 @@ CloudFormation do
|
|
176
196
|
@cfn.outputs.each do |out|
|
177
197
|
%>
|
178
198
|
|
179
|
-
Output(<%= out.name
|
199
|
+
Output('<%= out.name %>') do
|
180
200
|
<%
|
181
201
|
if out.condition
|
182
202
|
%>
|
183
|
-
Condition(<%= out.condition
|
203
|
+
Condition('<%= out.condition %>')
|
184
204
|
<%
|
185
205
|
end
|
186
206
|
%>
|
187
207
|
<%
|
188
208
|
if out.description
|
189
209
|
%>
|
190
|
-
Description
|
210
|
+
Description '<%= out.description %>'
|
191
211
|
<%
|
192
212
|
end
|
193
213
|
%>
|
194
214
|
<%
|
195
215
|
if out.value
|
196
216
|
if out.value.instance_of? String
|
197
|
-
value = out.value
|
217
|
+
value = '\'' + out.value + '\''
|
198
218
|
else
|
199
|
-
value = out.value.ai
|
219
|
+
value = out.value.ai.gsub('"', '\'')
|
200
220
|
end
|
201
221
|
%>
|
202
|
-
Value
|
222
|
+
Value <%= value %>
|
203
223
|
<%
|
204
224
|
end
|
205
225
|
%>
|
data/lib/cloudformation.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'extlib'
|
2
|
+
require 'psych'
|
2
3
|
class CloudFormation
|
3
4
|
|
4
5
|
ELEMENTS = [
|
@@ -15,24 +16,29 @@ class CloudFormation
|
|
15
16
|
|
16
17
|
attr_reader(*ELEMENTS)
|
17
18
|
|
18
|
-
def initialize(
|
19
|
+
def initialize(cfn_string)
|
20
|
+
cfn_hash = Psych.safe_load(cfn_string)
|
19
21
|
ELEMENTS.each do |e|
|
20
22
|
key = e.to_s.camel_case
|
21
23
|
if key =~ /^Aws/
|
22
24
|
key = key.sub(/^Aws/, "AWS")
|
23
25
|
end
|
24
26
|
|
25
|
-
if
|
26
|
-
attr = parse_element(e,
|
27
|
+
if cfn_hash[key]
|
28
|
+
attr = parse_element(e, cfn_hash[key])
|
27
29
|
instance_variable_set("@" + e.to_s, attr)
|
28
30
|
end
|
29
31
|
end
|
32
|
+
rescue Psych::DisallowedClass => error
|
33
|
+
raise YamlValueTypeError.new "Unsupported YAML value type found: only scalar values supported. #{error.message}"
|
34
|
+
rescue Psych::Exception => error
|
35
|
+
raise YamlSyntaxError.new "Syntax error in template. #{error.message}"
|
30
36
|
end
|
31
37
|
|
32
38
|
private
|
33
|
-
def parse_element(elm_name,
|
39
|
+
def parse_element(elm_name, cfn_hash)
|
34
40
|
function = parser(elm_name)
|
35
|
-
send(function, elm_name,
|
41
|
+
send(function, elm_name, cfn_hash)
|
36
42
|
end
|
37
43
|
|
38
44
|
def parser(name)
|
@@ -46,27 +52,27 @@ class CloudFormation
|
|
46
52
|
end
|
47
53
|
end
|
48
54
|
|
49
|
-
def simple_parser(name,
|
50
|
-
|
55
|
+
def simple_parser(name, cfn_hash)
|
56
|
+
cfn_hash
|
51
57
|
end
|
52
58
|
|
53
|
-
def complex_parser(name,
|
59
|
+
def complex_parser(name, cfn_hash)
|
54
60
|
elms = []
|
55
61
|
case name
|
56
62
|
when :metadata
|
57
|
-
|
63
|
+
cfn_hash.each_pair { |k, v| elms << Metadata.new(k, v) }
|
58
64
|
when :rules
|
59
|
-
|
65
|
+
cfn_hash.each_pair { |k, v| elms << Rules.new(k, v) }
|
60
66
|
when :parameters
|
61
|
-
|
67
|
+
cfn_hash.each_pair { |k, v| elms << Parameter.new(k, v) }
|
62
68
|
when :resources
|
63
|
-
|
69
|
+
cfn_hash.each_pair { |k, v| elms << Resource.new(k, v) }
|
64
70
|
when :outputs
|
65
|
-
|
71
|
+
cfn_hash.each_pair { |k, v| elms << Output.new(k, v) }
|
66
72
|
when :mappings
|
67
|
-
|
73
|
+
cfn_hash.each_pair { |k, v| elms << Mapping.new(k, v) }
|
68
74
|
when :conditions
|
69
|
-
|
75
|
+
cfn_hash.each_pair { |k, v| elms << Condition.new(k, v) }
|
70
76
|
end
|
71
77
|
return elms
|
72
78
|
end
|
data/lib/condition.rb
CHANGED
data/lib/error.rb
ADDED
data/lib/intrinsic_function.rb
CHANGED
@@ -20,11 +20,11 @@ class IntrinsicFunction
|
|
20
20
|
private
|
21
21
|
def fn_base64
|
22
22
|
if @parameters.instance_of? String
|
23
|
-
value =
|
23
|
+
value = "'#{@parameters}'"
|
24
24
|
else
|
25
25
|
value = @parameters.ai
|
26
26
|
end
|
27
|
-
return "FnBase64
|
27
|
+
return "FnBase64 '#{value}'"
|
28
28
|
end
|
29
29
|
|
30
30
|
def fn_select
|
@@ -32,7 +32,7 @@ class IntrinsicFunction
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def ref
|
35
|
-
return "Ref(
|
35
|
+
return "Ref('#{@parameters.gsub('\''){'\\\''}}')"
|
36
36
|
end
|
37
37
|
|
38
38
|
def fn_and
|
@@ -41,13 +41,13 @@ class IntrinsicFunction
|
|
41
41
|
|
42
42
|
def fn_equals
|
43
43
|
if @parameters[0].instance_of? String
|
44
|
-
arg1 = '
|
44
|
+
arg1 = '\'' + @parameters[0].gsub('\''){'\\\''} + '\''
|
45
45
|
else
|
46
46
|
arg1 = @parameters[0].ai
|
47
47
|
end
|
48
48
|
|
49
49
|
if @parameters[1].instance_of? String
|
50
|
-
arg2 = '
|
50
|
+
arg2 = '\'' + @parameters[1].gsub('\''){'\\\''} + '\''
|
51
51
|
else
|
52
52
|
arg2 = @parameters[1].ai
|
53
53
|
end
|
@@ -56,15 +56,15 @@ class IntrinsicFunction
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def fn_if
|
59
|
-
cond_name = '
|
59
|
+
cond_name = '\'' + @parameters[0].gsub('\''){'\\\''} + '\''
|
60
60
|
if @parameters[1].instance_of? String
|
61
|
-
true_value = '
|
61
|
+
true_value = '\'' + @parameters[1].gsub('\''){'\\\''} + '\''
|
62
62
|
else
|
63
63
|
true_value = @parameters[1].ai
|
64
64
|
end
|
65
65
|
|
66
66
|
if @parameters[2].instance_of? String
|
67
|
-
false_value = '
|
67
|
+
false_value = '\'' + @parameters[2].gsub('\''){'\\\''} + '\''
|
68
68
|
else
|
69
69
|
false_value = @parameters[2].ai
|
70
70
|
end
|
@@ -80,16 +80,16 @@ class IntrinsicFunction
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def fn_find_in_map
|
83
|
-
map_name = '
|
83
|
+
map_name = '\'' + @parameters[0] + '\''
|
84
84
|
|
85
85
|
if @parameters[1].instance_of? String
|
86
|
-
top_level_key = '
|
86
|
+
top_level_key = '\'' + @parameters[1] + '\''
|
87
87
|
else
|
88
88
|
top_level_key = @parameters[1].ai
|
89
89
|
end
|
90
90
|
|
91
91
|
if @parameters[2].instance_of? String
|
92
|
-
sec_level_key = '
|
92
|
+
sec_level_key = '\'' + @parameters[2] + '\''
|
93
93
|
else
|
94
94
|
sec_level_key = @parameters[2].ai
|
95
95
|
end
|
@@ -98,26 +98,36 @@ class IntrinsicFunction
|
|
98
98
|
end
|
99
99
|
|
100
100
|
def fn_get_att
|
101
|
-
resource_name = '
|
102
|
-
attr_name = '
|
101
|
+
resource_name = '\'' + @parameters[0] + '\''
|
102
|
+
attr_name = '\'' + @parameters[1] + '\''
|
103
103
|
return "FnGetAtt(#{resource_name}, #{attr_name})"
|
104
104
|
end
|
105
105
|
|
106
106
|
def fn_join
|
107
|
-
seperator = '
|
107
|
+
seperator = '\'' + @parameters[0].gsub('\''){'\\\''} + '\''
|
108
108
|
values = @parameters[1].ai
|
109
109
|
return "FnJoin(#{seperator}, #{values})"
|
110
110
|
end
|
111
111
|
|
112
112
|
def fn_sub
|
113
|
-
|
114
|
-
|
115
|
-
|
113
|
+
if @parameters.instance_of? String
|
114
|
+
value = '"' + @parameters.gsub('"'){'\\"'} + '"'
|
115
|
+
return "FnSub(#{value})"
|
116
|
+
else
|
117
|
+
origin = '"' + @parameters[0].gsub('"'){'\\"'} + '"'
|
118
|
+
values = @parameters[1].ai
|
119
|
+
return "FnSub(#{origin}, #{values})"
|
120
|
+
end
|
116
121
|
end
|
117
122
|
|
118
123
|
def fn_split
|
119
124
|
delimiter = '"' + @parameters[0].gsub('"'){'\\"'} + '"'
|
120
|
-
value = '"' + @parameters[1] + '"'
|
125
|
+
# value = '"' + @parameters[1] + '"'
|
126
|
+
if @parameters[1].instance_of? String
|
127
|
+
value = '"' + @parameters[1] + '"'
|
128
|
+
else
|
129
|
+
value = @parameters[1].ai
|
130
|
+
end
|
121
131
|
return "FnSplit(#{delimiter}, #{value})"
|
122
132
|
end
|
123
133
|
|
@@ -128,7 +138,7 @@ class IntrinsicFunction
|
|
128
138
|
|
129
139
|
def fn_get_a_zs
|
130
140
|
if @parameters.instance_of? String
|
131
|
-
value = '
|
141
|
+
value = '\'' + @parameters.gsub('\''){'\\\''} + '\''
|
132
142
|
else
|
133
143
|
value = @parameters.ai
|
134
144
|
end
|
@@ -136,5 +146,8 @@ class IntrinsicFunction
|
|
136
146
|
return "FnGetAZs(#{value})"
|
137
147
|
end
|
138
148
|
|
149
|
+
def fn_cidr
|
150
|
+
return "FnCidr(#{@parameters.ai})"
|
151
|
+
end
|
139
152
|
|
140
153
|
end
|
data/lib/mapping.rb
CHANGED
data/lib/metadata.rb
CHANGED
data/lib/output.rb
CHANGED
@@ -9,16 +9,16 @@ class Output
|
|
9
9
|
|
10
10
|
attr_reader(:name, *ATTRIBUTES)
|
11
11
|
|
12
|
-
def initialize(name,
|
12
|
+
def initialize(name, cfn_hash)
|
13
13
|
@name = name
|
14
|
-
ATTRIBUTES.each {|a| attribute(a,
|
14
|
+
ATTRIBUTES.each {|a| attribute(a, cfn_hash)}
|
15
15
|
end
|
16
16
|
|
17
17
|
private
|
18
|
-
def attribute(name,
|
18
|
+
def attribute(name, cfn_hash)
|
19
19
|
key = name.to_s.camel_case
|
20
|
-
if
|
21
|
-
value =
|
20
|
+
if cfn_hash[key]
|
21
|
+
value = parse_cfn(cfn_hash[key])
|
22
22
|
instance_variable_set("@" + name.to_s, value)
|
23
23
|
end
|
24
24
|
end
|
data/lib/parameter.rb
CHANGED
@@ -17,11 +17,11 @@ class Parameter
|
|
17
17
|
|
18
18
|
attr_reader(*ELEMENTS)
|
19
19
|
|
20
|
-
def initialize(name,
|
20
|
+
def initialize(name, cfn_hash)
|
21
21
|
@name = name
|
22
22
|
ELEMENTS.each do |e|
|
23
23
|
key_name = e.to_s.camel_case
|
24
|
-
instance_variable_set('@' + e.to_s,
|
24
|
+
instance_variable_set('@' + e.to_s, cfn_hash[key_name]) if cfn_hash[key_name]
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
data/lib/resource.rb
CHANGED
@@ -14,10 +14,10 @@ class Resource
|
|
14
14
|
|
15
15
|
attr_reader(:name, *ATTRIBUTES)
|
16
16
|
|
17
|
-
def initialize(name,
|
17
|
+
def initialize(name, cfn_hash)
|
18
18
|
@name = name
|
19
19
|
ATTRIBUTES.each do |a|
|
20
|
-
send(attribute_type(a),
|
20
|
+
send(attribute_type(a), cfn_hash, a.to_s)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -37,18 +37,18 @@ class Resource
|
|
37
37
|
return type
|
38
38
|
end
|
39
39
|
|
40
|
-
def complex_attribute(
|
41
|
-
if
|
42
|
-
values =
|
43
|
-
|
40
|
+
def complex_attribute(cfn_hash, name)
|
41
|
+
if cfn_hash[name.camel_case]
|
42
|
+
values = cfn_hash[name.camel_case].merge do |k, v|
|
43
|
+
parse_cfn(v)
|
44
44
|
end
|
45
45
|
instance_variable_set('@' + name, values)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
def basic_attribute(
|
50
|
-
if
|
51
|
-
instance_variable_set('@' + name,
|
49
|
+
def basic_attribute(cfn_hash, name)
|
50
|
+
if cfn_hash[name.camel_case]
|
51
|
+
instance_variable_set('@' + name, parse_cfn(cfn_hash[name.camel_case]))
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
data/lib/rules.rb
CHANGED
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cfn2dsl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Yung
|
8
8
|
- Valen Gunawan
|
9
|
+
- Cam Maxwell
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date:
|
13
|
+
date: 2019-08-19 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: extlib
|
@@ -31,14 +32,14 @@ dependencies:
|
|
31
32
|
requirements:
|
32
33
|
- - '='
|
33
34
|
- !ruby/object:Gem::Version
|
34
|
-
version: 1.
|
35
|
+
version: 1.8.0
|
35
36
|
type: :runtime
|
36
37
|
prerelease: false
|
37
38
|
version_requirements: !ruby/object:Gem::Requirement
|
38
39
|
requirements:
|
39
40
|
- - '='
|
40
41
|
- !ruby/object:Gem::Version
|
41
|
-
version: 1.
|
42
|
+
version: 1.8.0
|
42
43
|
- !ruby/object:Gem::Dependency
|
43
44
|
name: erubis
|
44
45
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,7 +54,7 @@ dependencies:
|
|
53
54
|
- - '='
|
54
55
|
- !ruby/object:Gem::Version
|
55
56
|
version: 2.7.0
|
56
|
-
description: A tool to convert CloudFormation
|
57
|
+
description: A tool to convert CloudFormation templates into a Ruby DSL cfndsl
|
57
58
|
email: jwrong@gmail.com
|
58
59
|
executables:
|
59
60
|
- cfn2dsl
|
@@ -66,6 +67,7 @@ files:
|
|
66
67
|
- lib/cfndsl.erb
|
67
68
|
- lib/cloudformation.rb
|
68
69
|
- lib/condition.rb
|
70
|
+
- lib/error.rb
|
69
71
|
- lib/intrinsic_function.rb
|
70
72
|
- lib/mapping.rb
|
71
73
|
- lib/metadata.rb
|
@@ -87,7 +89,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
87
89
|
requirements:
|
88
90
|
- - ">="
|
89
91
|
- !ruby/object:Gem::Version
|
90
|
-
version: 2.
|
92
|
+
version: 2.4.4
|
91
93
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
94
|
requirements:
|
93
95
|
- - ">="
|
@@ -95,8 +97,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
97
|
version: '0'
|
96
98
|
requirements: []
|
97
99
|
rubyforge_project:
|
98
|
-
rubygems_version: 2.
|
100
|
+
rubygems_version: 2.7.8
|
99
101
|
signing_key:
|
100
102
|
specification_version: 4
|
101
|
-
summary: A tool to convert CloudFormation
|
103
|
+
summary: A tool to convert CloudFormation templates into a Ruby DSL cfndsl
|
102
104
|
test_files: []
|