Class: Lono::Cfn::Update

Inherits:
Base
  • Object
show all
Defined in:
lib/lono/cfn/update.rb

Instance Method Summary collapse

Methods inherited from Base

#append_suffix, #build_scripts, #capabilities, #check_files, #check_for_errors, #command_with_iam, #convention_path, #exit_unless_updatable!, #generate_all, #generate_params, #generate_templates, #get_source_path, #initialize, #prompt_for_iam, #quit, #random_suffix, #remove_suffix, #run, #s3_folder, #set_template_body!, #show_parameters, #stack_name_suffix, #stack_status, #starting_message, #status, #switch_current, #upload_files, #upload_scripts, #upload_templates

Methods included from Util

#are_you_sure?

Methods included from AwsService

#cfn, #stack_exists?, #testing_update?

Constructor Details

This class inherits a constructor from Lono::Cfn::Base

Instance Method Details

#diffObject



56
57
58
# File 'lib/lono/cfn/update.rb', line 56

def diff
  @diff ||= Lono::Cfn::Diff.new(@stack_name, @options.merge(lono: false, mute_params: true, mute_using: true))
end

#save_stack(params) ⇒ Object

save_stack is the interface method



3
4
5
# File 'lib/lono/cfn/update.rb', line 3

def save_stack(params)
  update_stack(params)
end

#standard_update(params) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/lono/cfn/update.rb', line 39

def standard_update(params)
  params = {
    stack_name: @stack_name,
    parameters: params,
    capabilities: capabilities, # ["CAPABILITY_IAM", "CAPABILITY_NAMED_IAM"]
    disable_rollback: !@options[:rollback],
  }
  set_template_body!(params)
  show_parameters(params, "cfn.update_stack")
  begin
    cfn.update_stack(params)
  rescue Aws::CloudFormation::Errors::ValidationError => e
    puts "ERROR: #{e.message}".red
    error = true
  end
end

#update_stack(params) ⇒ Object

aws cloudformation update-stack –stack-name prod-hi-123456789 –parameters file://output/params/prod-hi-123456789.json –template-body file://output/prod-hi.json



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
# File 'lib/lono/cfn/update.rb', line 8

def update_stack(params)
  message = "Updating #{@stack_name} stack"
  if @options[:noop]
    puts "NOOP #{message}"
    return
  end

  unless stack_exists?(@stack_name)
    puts "Cannot update a stack because the #{@stack_name} does not exists."
    return
  end
  exit_unless_updatable!(stack_status(@stack_name))

  options = @options.merge(lono: false, mute_params: true, mute_using: true, keep: true)
  # create new copy of preview when update_stack is called because of IAM retry logic
  preview = Lono::Cfn::Preview.new(@stack_name, options)

  error = nil
  diff.run if @options[:diff]
  preview.run if @options[:preview]
  are_you_sure?(@stack_name, :update)

  if @options[:change_set] # defaults to this
    message << " via change set: #{preview.change_set_name}"
    preview.execute_change_set
  else
    standard_update(params)
  end
  puts message unless @options[:mute] || error
end