Class: Lono::Sets::Update

Inherits:
Base show all
Includes:
Summarize
Defined in:
lib/lono/sets/update.rb

Instance Method Summary collapse

Methods included from Summarize

#summarize

Methods inherited from Base

#build_options, #exit_unless_updatable!, #operation_preferences, #run

Methods inherited from Cfn::Base

#capabilities, #check_registration, #command_with_iam, #continue_update_rollback, #continue_update_rollback_sure?, #delete_rollback_stack, #exit_unless_updatable!, #generate_all, #pretty_path, #prompt_for_iam, #quit, #rerun_with_iam?, #run, #set_template_url!, #show_options, #stack_status, #starting_message, #status, #tags

Methods included from Utils::Sure

#sure?

Methods included from AwsServices

#cfn, #ec2, #iam, #s3, #s3_presigner, #s3_resource, #sts

Methods included from AwsServices::Helper

#rollback_complete?, #testing_update?

Methods included from AwsServices::StackSet

#find_stack_set, #stack_set_exists?

Methods included from AwsServices::Stack

#find_stack, #stack_exists?

Methods inherited from AbstractBase

#initialize, #reinitialize, #template_path

Methods included from Blueprint::Root

#find_blueprint_root, #set_blueprint_root

Constructor Details

This class inherits a constructor from Lono::AbstractBase

Instance Method Details

#codediff_previewObject



71
72
73
# File 'lib/lono/sets/update.rb', line 71

def codediff_preview
  Lono::Sets::Preview::Codediff.new(@options.merge(mute_params: true, mute_using: true))
end

#long_descObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/lono/sets/update.rb', line 56

def long_desc
  info = stack_instances.inject({}) do |result, instance|
    result[instance.] ||= []
    result[instance.] << instance.region
    result
  end
  message = "Will deploy to:\n"
  info.each do |, regions|
    message << "  account: #{}\n"
    message << "  regions: #{regions.join(",")}\n"
  end
  message << "\nNumber of stack instances to be updated: #{stack_instances.size}"
  message
end

#param_previewObject



76
77
78
# File 'lib/lono/sets/update.rb', line 76

def param_preview
  Lono::Sets::Preview::Param.new(@options)
end

#saveObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/lono/sets/update.rb', line 5

def save
  message = "Updating #{@stack} stack set"
  if @options[:noop]
    puts "NOOP #{message}"
    return
  end

  unless stack_set_exists?(@stack)
    puts "ERROR: Cannot update a stack set because #{@stack} does not exists.".color(:red)
    return
  end
  exit_unless_updatable!

  param_preview.run if @options[:param_preview]
  codediff_preview.run if @options[:codediff_preview]
  # changeset preview not supported for stack sets

  options = build_options
  show_options(options, "cfn.update_stack_set")

  if stack_instances.empty?
    puts <<~EOL
      NOTE: There are 0 stack instances associated with the #{@stack} stack set.
      Will update the stack set template but there no instances to be updated.
      Add `configs/#{@blueprint}/accounts` and `configs/#{@blueprint}/regions` settings
      and use `lono sets instances sync` to add stack instances.
    EOL
  else
    sure?("Are you sure you want to update the #{@stack} stack set?", long_desc)
  end

  resp = cfn.update_stack_set(options)
  operation_id = resp[:operation_id]
  puts message unless @options[:mute]

  return true if @options[:noop] || !@options[:wait]

  Lono::Sets::Status::Instance::Base.show_time_progress = true
  Lono::Sets::Status::Instance::Base.delay_factor = stack_instances.size
  status = Status.new(@options.merge(operation_id: operation_id))
  success = status.wait
  summarize(operation_id)
  exit 1 unless success
  success
end

#stack_instancesObject



51
52
53
# File 'lib/lono/sets/update.rb', line 51

def stack_instances
  Lono::Sets::Status::Instances.new(@options).stack_instances
end