Class: LonoCfn::Update

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

Instance Method Summary collapse

Methods inherited from Base

#check_files, #check_for_errors, #convention_path, #detect_format, #exist_unless_updatable, #generate_all, #generate_params, #generate_templates, #get_source_path, #initialize, #quit, #run, #stack_status

Methods included from Util

#are_you_sure?

Methods included from AwsServices

#cfn, #stack_exists?, #testing_update?

Constructor Details

This class inherits a constructor from LonoCfn::Base

Instance Method Details

#change_set_updateObject



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

def change_set_update
  preview.execute_change_set
end

#diffObject



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

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

#previewObject



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

def preview
  options = @options.merge(lono: false, mute_params: true, mute_using: true, keep: true)
  @preview ||= Preview.new(@stack_name, options)
end

#save_stack(params) ⇒ Object

save_stack is the interface method



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

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
# 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: ["CAPABILITY_IAM"]
    )
  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



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 9

def update_stack(params)
  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))

  message = "Updating #{@stack_name} stack"
  error = nil
  if @options[:noop]
    message = "NOOP #{message}"
  else
    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
  end
  puts message unless @options[:mute] || error
end