Class: Lono::Cfn::Update

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

Instance Attribute Summary

Attributes inherited from Base

#randomize_stack_name

Instance Method Summary collapse

Methods inherited from Base

#capabilities, #check_files, #check_for_errors, #command_with_iam, #convention_path, #derandomize, #detect_format, #exist_unless_updatable, #generate_all, #generate_params, #generate_templates, #get_source_path, #initialize, #prompt_for_iam, #quit, #randomize, #randomize_stack_name?, #run, #stack_status, #upload_templates

Methods included from Util

#are_you_sure?

Methods included from AwsServices

#cfn, #stack_exists?, #testing_update?

Constructor Details

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

Instance Method Details

#change_set_updateObject



60
61
62
# File 'lib/lono/cfn/update.rb', line 60

def change_set_update
  preview.execute_change_set
end

#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

#previewObject



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

def preview
  options = @options.merge(lono: false, mute_params: true, mute_using: true, keep: true)
  @preview ||= Lono::Cfn::Preview.new(@stack_name, options)
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



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/lono/cfn/update.rb', line 35

def standard_update(params)
  template_body = IO.read(@template_path)
  begin
    cfn.update_stack(
      stack_name: @stack_name,
      template_body: template_body,
      parameters: params,
      capabilities: capabilities, # ["CAPABILITY_IAM", "CAPABILITY_NAMED_IAM"]
      disable_rollback: !@options[:rollback],
    )
  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
# 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
  exist_unless_updatable(stack_status(@stack_name))

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

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