cloudformation-ruby-dsl 0.4.3 → 0.4.4
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.
- data/README.md +1 -1
- data/lib/cloudformation-ruby-dsl/cfntemplate.rb +24 -18
- data/lib/cloudformation-ruby-dsl/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -29,7 +29,7 @@ To convert existing JSON templates to use the DSL, run
|
|
29
29
|
You may need to preface this with `bundle exec` if you installed via Bundler.
|
30
30
|
|
31
31
|
Make the resulting file executable (`chmod +x [NEW_NAME.rb]`). It can respond to the following subcommands (which are listed if you run without parameters):
|
32
|
-
- `expand`: output the JSON template to the command line (takes optional `--
|
32
|
+
- `expand`: output the JSON template to the command line (takes optional `--nopretty` to minimize the output)
|
33
33
|
- `diff`: compare output with existing JSON for a stack
|
34
34
|
- `cfn-validate-template`: run validation against the stack definition
|
35
35
|
- `cfn-create-stack`: create a new stack from the output
|
@@ -36,19 +36,18 @@ end
|
|
36
36
|
def cfn_parse_args
|
37
37
|
parameters = {}
|
38
38
|
region = ENV['EC2_REGION'] || ENV['AWS_DEFAULT_REGION'] || 'us-east-1'
|
39
|
-
|
39
|
+
nopretty = false
|
40
40
|
ARGV.slice_before(/^--/).each do |name, value|
|
41
|
-
next unless value
|
42
41
|
case name
|
43
42
|
when '--parameters'
|
44
43
|
parameters = Hash[value.split(/;/).map { |pair| pair.split(/=/, 2) }]
|
45
44
|
when '--region'
|
46
45
|
region = value
|
47
|
-
when '--
|
48
|
-
|
46
|
+
when '--nopretty'
|
47
|
+
nopretty = true
|
49
48
|
end
|
50
49
|
end
|
51
|
-
[parameters, region,
|
50
|
+
[parameters, region, nopretty]
|
52
51
|
end
|
53
52
|
|
54
53
|
def cfn_cmd(template)
|
@@ -71,21 +70,25 @@ def cfn_cmd(template)
|
|
71
70
|
# The command line string looks like: --tag "Key=key; Value=value" --tag "Key2=key2; Value2=value"
|
72
71
|
cfn_tags_options = cfn_tags.sort.map { |tag| ["--tag", "Key=%s; Value=%s" % tag.split('=')] }.flatten
|
73
72
|
|
73
|
+
# example: <template.rb> cfn-create-stack my-stack-name --parameters "Env=prod" --region eu-west-1
|
74
|
+
# Execute the AWS CLI cfn-cmd command to validate/create/update a CloudFormation stack.
|
75
|
+
if action == 'diff' or (action == 'expand' and not template.nopretty)
|
76
|
+
template_string = JSON.pretty_generate(template)
|
77
|
+
else
|
78
|
+
template_string = JSON.generate(template)
|
79
|
+
end
|
80
|
+
|
74
81
|
if action == 'expand'
|
75
|
-
# Write the pretty-printed JSON template to stdout and exit. [--
|
76
|
-
# example: <template.rb> expand --parameters "Env=prod" --region eu-west-1 --
|
77
|
-
if template.
|
78
|
-
puts
|
82
|
+
# Write the pretty-printed JSON template to stdout and exit. [--nopretty] option writes output with minimal whitespace
|
83
|
+
# example: <template.rb> expand --parameters "Env=prod" --region eu-west-1 --nopretty
|
84
|
+
if template.nopretty
|
85
|
+
puts template_string
|
79
86
|
else
|
80
|
-
puts
|
87
|
+
puts template_string
|
81
88
|
end
|
82
|
-
|
83
89
|
exit(true)
|
84
90
|
end
|
85
91
|
|
86
|
-
# example: <template.rb> cfn-create-stack my-stack-name --parameters "Env=prod" --region eu-west-1
|
87
|
-
# Execute the AWS CLI cfn-cmd command to validate/create/update a CloudFormation stack.
|
88
|
-
template_string = JSON.generate(template)
|
89
92
|
temp_file = File.absolute_path("#{$PROGRAM_NAME}.expanded.json")
|
90
93
|
File.write(temp_file, template_string)
|
91
94
|
|
@@ -110,7 +113,10 @@ def cfn_cmd(template)
|
|
110
113
|
|
111
114
|
# Run CloudFormation commands to describe the existing stack
|
112
115
|
cfn_options_string = cfn_options.map { |arg| "'#{arg}'" }.join(' ')
|
113
|
-
|
116
|
+
old_template_raw = exec_capture_stdout("cfn-cmd cfn-get-template #{cfn_options_string}")
|
117
|
+
# ec2 template output is not valid json: TEMPLATE "<json>\n"\n
|
118
|
+
old_template_object = JSON.parse(old_template_raw[11..-3])
|
119
|
+
old_template_string = JSON.pretty_generate(old_template_object)
|
114
120
|
old_stack_attributes = exec_describe_stack(cfn_options_string)
|
115
121
|
old_tags_string = old_stack_attributes["TAGS"]
|
116
122
|
old_parameters_string = old_stack_attributes["PARAMETERS"]
|
@@ -127,7 +133,7 @@ def cfn_cmd(template)
|
|
127
133
|
old_temp_file = File.absolute_path("#{$PROGRAM_NAME}.current.json")
|
128
134
|
new_temp_file = File.absolute_path("#{$PROGRAM_NAME}.expanded.json")
|
129
135
|
File.write(old_temp_file, old_tags_string + old_parameters_string + old_template_string)
|
130
|
-
File.write(new_temp_file, tags_string + parameters_string +
|
136
|
+
File.write(new_temp_file, tags_string + parameters_string + template_string)
|
131
137
|
|
132
138
|
# Compare templates
|
133
139
|
system(*["diff"] + diff_options + [old_temp_file, new_temp_file])
|
@@ -261,10 +267,10 @@ end
|
|
261
267
|
|
262
268
|
# Core interpreter for the DSL
|
263
269
|
class TemplateDSL < JsonObjectDSL
|
264
|
-
attr_reader :parameters, :aws_region, :
|
270
|
+
attr_reader :parameters, :aws_region, :nopretty
|
265
271
|
|
266
272
|
def initialize()
|
267
|
-
@parameters, @aws_region, @
|
273
|
+
@parameters, @aws_region, @nopretty = cfn_parse_args
|
268
274
|
super
|
269
275
|
end
|
270
276
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudformation-ruby-dsl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -16,7 +16,7 @@ authors:
|
|
16
16
|
autorequire:
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
|
-
date: 2014-
|
19
|
+
date: 2014-07-11 00:00:00.000000000 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: detabulator
|