sfn 1.1.10 → 1.1.12

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: 8ee7d09945927cfc75821041ef90090dba2ef9c0
4
- data.tar.gz: fad23bceb0be9ba52eab93f31e51d508c5109de1
3
+ metadata.gz: e7c94cea72644d2789ca1bbc6bb3a235e6f45356
4
+ data.tar.gz: 67108e9ccf029399a1892ed96e520db1515b4216
5
5
  SHA512:
6
- metadata.gz: adac24b09b2ab1681f88fc4c60d41fb21ca9026e4246527ff63a337c1300de2a8186cfab28b88df7599a2ae092206493ea29e053cd3d1e1dccd3b117844ae827
7
- data.tar.gz: 55e2b6bdc3cbd30512c8818c2551f2c8253dfc2f5058b03b557816c2cdc8afe48e01c52f2ba2daa057e61b71e70a4791ddac17374b2a8c78bf084dbf7d021bc6
6
+ metadata.gz: aff9a0b880bf2173a721107d5ad9fbea43af78f6b1aa6ed2e650a705b298679e7287355684cbca221cc19fd3e433403cf3eff0294483827fcaa1aee9aecd4dd6
7
+ data.tar.gz: eabc758d5854532e50aa9b1905d2518b3d6f7e37bcc79a3c1046308ce1e4d702f542ceb87768a3df14ea96c4a761cd5bfaa1fa68080d660e73616dac1fac5bf3
@@ -1,3 +1,8 @@
1
+ ## v1.1.12
2
+ * [enhancement] Include updated time information on stack list
3
+ * [enhancement] Support pseudo-parameters in update planning
4
+ * AWS only as it is currently the only implementation
5
+
1
6
  ## v1.1.10
2
7
  * [enhancement] Better configuration related errors
3
8
  * [fix] Planning display on stack removal (#75)
@@ -80,8 +80,10 @@ Builtin callbacks distributed with `sfn`:
80
80
 
81
81
  #### Stack Policy Callback
82
82
 
83
- The Stack Policy Callback utilizes the [policy feature][sparkle_policy]
84
- built into the [SparkleFormation][sparkle_formation] library.
83
+ The Stack Policy Callback utilizes the [policy feature](http://www.sparkleformation.io/docs/sparkle_formation/stack-policies.html)
84
+ built into the [SparkleFormation](http://www.sparkleformation.io/docs/sparkle_formation)
85
+ library.
86
+
85
87
  To enable the callback:
86
88
 
87
89
  ~~~ruby
@@ -36,7 +36,7 @@ $ gem install sfn
36
36
  or, if you use [Bundler](http://bundler.io/), add the following to your Gemfile:
37
37
 
38
38
  ~~~sh
39
- gem sfn', '~> 1.0.4'
39
+ gem 'sfn'
40
40
  ~~~
41
41
 
42
42
  See [Configuration](configuration.md) and [Usage](usage.md) for further instructions.
@@ -48,9 +48,9 @@ module Sfn
48
48
  # @return [Array<String>] default attributes to display
49
49
  def default_attributes
50
50
  if(provider.connection.provider == :aws)
51
- %w(name created status template_description)
51
+ %w(name created updated status template_description)
52
52
  else
53
- %w(name created status description)
53
+ %w(name created updated status description)
54
54
  end
55
55
  end
56
56
 
@@ -164,57 +164,58 @@ module Sfn
164
164
 
165
165
 
166
166
  def print_plan_result(info, names=[])
167
- said_things = false
167
+ said_any_things = false
168
168
  unless(info[:stacks].empty?)
169
169
  info[:stacks].each do |s_name, s_info|
170
170
  said_things = print_plan_result(s_info, [*names, s_name].compact)
171
171
  end
172
172
  end
173
173
  unless(names.flatten.compact.empty?)
174
+ said_things = false
174
175
  ui.puts
175
176
  ui.puts " #{ui.color('Update plan for:', :bold)} #{ui.color(names.join(' > '), :blue)}"
176
177
  unless(info[:unknown].empty?)
177
178
  ui.puts " #{ui.color('!!! Unknown update effect:', :red, :bold)}"
178
179
  print_plan_items(info, :unknown, :red)
179
180
  ui.puts
180
- said_things = true
181
+ said_any_things = said_things = true
181
182
  end
182
183
  unless(info[:unavailable].empty?)
183
184
  ui.puts " #{ui.color('Update request not allowed:', :red, :bold)}"
184
185
  print_plan_items(info, :unavailable, :red)
185
186
  ui.puts
186
- said_things = true
187
+ said_any_things = said_things = true
187
188
  end
188
189
  unless(info[:replace].empty?)
189
190
  ui.puts " #{ui.color('Resources to be replaced:', :red, :bold)}"
190
191
  print_plan_items(info, :replace, :red)
191
192
  ui.puts
192
- said_things = true
193
+ said_any_things = said_things = true
193
194
  end
194
195
  unless(info[:interrupt].empty?)
195
196
  ui.puts " #{ui.color('Resources to be interrupted:', :yellow, :bold)}"
196
197
  print_plan_items(info, :interrupt, :yellow)
197
198
  ui.puts
198
- said_things = true
199
+ said_any_things = said_things = true
199
200
  end
200
201
  unless(info[:removed].empty?)
201
202
  ui.puts " #{ui.color('Resources to be removed:', :red, :bold)}"
202
203
  print_plan_items(info, :removed, :red)
203
204
  ui.puts
204
- said_things = true
205
+ said_any_things = said_things = true
205
206
  end
206
207
  unless(info[:added].empty?)
207
208
  ui.puts " #{ui.color('Resources to be added:', :green, :bold)}"
208
209
  print_plan_items(info, :added, :green)
209
210
  ui.puts
210
- said_things = true
211
+ said_any_things = said_things = true
211
212
  end
212
213
  unless(said_things)
213
214
  ui.puts " #{ui.color('No resource lifecycle changes detected!', :green)}"
214
215
  ui.puts
215
216
  end
216
217
  end
217
- said_things
218
+ said_any_things
218
219
  end
219
220
 
220
221
  # Print planning items
@@ -247,6 +247,12 @@ module Sfn
247
247
  )
248
248
  unless(config[:plan])
249
249
  resource.properties.delete!(:stack)
250
+ else
251
+ (stack_definition['Resources'] || {}).each do |_, info|
252
+ if(valid_stack_types.include?(info['Type']))
253
+ info['Properties'].delete('Stack')
254
+ end
255
+ end
250
256
  end
251
257
  bucket = provider.connection.api_for(:storage).buckets.get(
252
258
  config[:nesting_bucket]
@@ -14,6 +14,8 @@ module Sfn
14
14
  attr_reader :arguments
15
15
  # @return [Miasma::Models::Orchestration::Stack] existing remote stack
16
16
  attr_reader :origin_stack
17
+ # @return [Hash] custom options
18
+ attr_reader :options
17
19
 
18
20
  # Create a new planner instance
19
21
  #
@@ -21,13 +23,15 @@ module Sfn
21
23
  # @param config [Smash]
22
24
  # @param arguments [Array<String>]
23
25
  # @param stack [Miasma::Models::Orchestration::Stack]
26
+ # @param opts [Hash]
24
27
  #
25
28
  # @return [self]
26
- def initialize(ui, config, arguments, stack)
29
+ def initialize(ui, config, arguments, stack, opts={})
27
30
  @ui = ui
28
31
  @config = config
29
32
  @arguments = arguments
30
33
  @origin_stack = stack
34
+ @options = opts
31
35
  end
32
36
 
33
37
  # Generate update report
@@ -1,6 +1,3 @@
1
- require 'pp'
2
-
3
-
4
1
  require 'sfn'
5
2
  require 'sparkle_formation/aws'
6
3
  require 'hashdiff'
@@ -13,11 +10,15 @@ module Sfn
13
10
  # Customized translator to dereference template
14
11
  class Translator < SparkleFormation::Translation
15
12
 
13
+ MAP = {}
14
+ REF_MAPPING = {}
15
+ FN_MAPPING = {}
16
+
16
17
  # @return [Array<String>] flagged items for value replacement
17
18
  attr_reader :flagged
18
19
 
19
20
  # Override to init flagged array
20
- def initialize(*_)
21
+ def initialize(template_hash, args={})
21
22
  super
22
23
  @flagged = []
23
24
  end
@@ -147,6 +148,21 @@ module Sfn
147
148
 
148
149
  protected
149
150
 
151
+ # Set global parameters available for all template translations.
152
+ # These are pseudo-parameters that are provided by the
153
+ # orchestration api runtime.
154
+ #
155
+ # @return [Hash]
156
+ def get_global_parameters(stack)
157
+ Smash.new(
158
+ 'AWS::Region' => stack.api.aws_region,
159
+ 'AWS::AccountId' => stack.id.split(':')[4],
160
+ 'AWS::NotificationARNs' => stack.notification_topics,
161
+ 'AWS::StackId' => stack.id,
162
+ 'AWS::StackName' => stack.name
163
+ ).merge(config.fetch(:planner, :global_parameters, {}))
164
+ end
165
+
150
166
  # Generate plan for stack
151
167
  #
152
168
  # @param stack [Miasma::Models::Orchestration::Stack]
@@ -166,7 +182,11 @@ module Sfn
166
182
  :n_outputs => []
167
183
  )
168
184
 
169
- origin_template = dereference_template("#{stack.data.checksum}_origin", stack.template, stack.parameters)
185
+ origin_template = dereference_template(
186
+ "#{stack.data.checksum}_origin",
187
+ stack.template,
188
+ stack.parameters.merge(get_global_parameters(stack))
189
+ )
170
190
 
171
191
  t_key = "#{stack.data.checksum}_#{stack.data.fetch(:logical_id, stack.name)}"
172
192
  run_stack_diff(stack, t_key, plan_results, origin_template, new_template, new_parameters)
@@ -227,23 +247,22 @@ module Sfn
227
247
  end
228
248
  end
229
249
 
230
- update_template = dereference_template(
231
- t_key, new_template.to_smash, new_parameters,
232
- plan_results[:replace].keys + plan_results[:unavailable].keys
233
- )
250
+ new_parameters.merge!(get_global_parameters(stack))
251
+
252
+ new_template_hash = new_template.to_smash
234
253
 
235
254
  o_nested_stacks = origin_template['Resources'].find_all do |s_name, s_val|
236
255
  is_stack?(s_val['Type'])
237
256
  end.map(&:first)
238
- n_nested_stacks = new_template['Resources'].find_all do |s_name, s_val|
257
+ n_nested_stacks = new_template_hash['Resources'].find_all do |s_name, s_val|
239
258
  is_stack?(s_val['Type'])
240
259
  end.map(&:first)
241
260
  [o_nested_stacks + n_nested_stacks].flatten.compact.uniq.each do |n_name|
242
261
  o_stack = stack.nested_stacks(false).detect{|s| s.data[:logical_id] == n_name}
243
- n_exists = is_stack?(update_template['Resources'].fetch(n_name, {})['Type'])
244
- n_template = update_template['Resources'].fetch(n_name, {}).fetch('Properties', {})['Stack']
245
- n_parameters = update_template['Resources'].fetch(n_name, {}).fetch('Properties', {})['Parameters']
246
- n_type = update_template['Resources'].fetch(n_name, {})['Type'] ||
262
+ n_exists = is_stack?(new_template_hash['Resources'].fetch(n_name, {})['Type'])
263
+ n_template = new_template_hash['Resources'].fetch(n_name, {}).fetch('Properties', {})['Stack']
264
+ n_parameters = new_template_hash['Resources'].fetch(n_name, {}).fetch('Properties', {}).fetch('Parameters', {})
265
+ n_type = new_template_hash['Resources'].fetch(n_name, {})['Type'] ||
247
266
  origin_template['Resources'][n_name]['Type']
248
267
  resource = Smash.new(
249
268
  :name => n_name,
@@ -267,9 +286,16 @@ module Sfn
267
286
  plan_results[:added][n_name] = resource
268
287
  end
269
288
  end
289
+
270
290
  n_nested_stacks.each do |ns_name|
271
- update_template['Resources'][ns_name]['Properties'].delete('Stack')
291
+ new_template_hash['Resources'][ns_name]['Properties'].delete('Stack')
272
292
  end
293
+
294
+ update_template = dereference_template(
295
+ t_key, new_template_hash, new_parameters,
296
+ plan_results[:replace].keys + plan_results[:unavailable].keys
297
+ )
298
+
273
299
  HashDiff.diff(origin_template, MultiJson.load(MultiJson.dump(update_template))).group_by do |item|
274
300
  item[1]
275
301
  end.each do |a_path, diff_items|
@@ -374,8 +400,14 @@ module Sfn
374
400
  flagged.each do |item|
375
401
  translator.flag_ref(item)
376
402
  end
377
- template['Resources'] = translator.dereference_processor(template['Resources'], ['Ref', 'Fn', 'DEREF'])
378
- template['Outputs'] = translator.dereference_processor(template['Outputs'], ['Ref', 'Fn', 'DEREF'])
403
+ template.keys.each do |t_key|
404
+ next if ['Outputs', 'Resources'].include?(t_key)
405
+ template[t_key] = translator.dereference_processor(template[t_key], ['Ref', 'Fn', 'DEREF', 'Fn::FindInMap'])
406
+ end
407
+ translator.original.replace(template)
408
+ template['Resources'] = translator.dereference_processor(template['Resources'], ['Ref', 'Fn', 'DEREF', 'Fn::FindInMap'])
409
+ template['Outputs'] = translator.dereference_processor(template['Outputs'], ['Ref', 'Fn', 'DEREF', 'Fn::FindInMap'])
410
+ translator.original.replace({})
379
411
  template
380
412
  end
381
413
 
@@ -388,7 +420,9 @@ module Sfn
388
420
  def translator_for(t_key, template=nil, parameters=nil)
389
421
  o_translator = translators[t_key]
390
422
  if(template)
391
- translator = Translator.new(template, :parameters => parameters)
423
+ translator = Translator.new(template,
424
+ :parameters => parameters
425
+ )
392
426
  if(o_translator)
393
427
  o_translator.flagged.each do |i|
394
428
  translator.flag_ref(i)
@@ -398,7 +432,9 @@ module Sfn
398
432
  o_translator = translator
399
433
  else
400
434
  unless(o_translator)
401
- o_translator = Translator.new({}, :parameters => {})
435
+ o_translator = Translator.new({},
436
+ :parameters => {}
437
+ )
402
438
  end
403
439
  end
404
440
  o_translator
@@ -1,4 +1,4 @@
1
1
  module Sfn
2
2
  # Current library version
3
- VERSION = Gem::Version.new('1.1.10')
3
+ VERSION = Gem::Version.new('1.1.12')
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sfn
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.10
4
+ version: 1.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Roberts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-10 00:00:00.000000000 Z
11
+ date: 2015-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bogo-cli