Class: Lono::Cfn::Update

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

Instance Method Summary collapse

Methods inherited from Base

#build_files, #build_scripts, #capabilities, #check_files, #check_for_errors, #command_with_iam, #continue_update_rollback, #continue_update_rollback_sure?, #delete_rollback_stack, #ensure_s3_bucket_exist, #exit_unless_updatable!, #generate_all, #generate_templates, #initialize, #param_generator, #post_process_templates, #pretty_path, #prompt_for_iam, #quit, #run, #set_template_body!, #show_parameters, #stack_status, #starting_message, #status, #switch_current, #tags, #upload_files, #upload_scripts, #upload_templates

Methods included from Util

#are_you_sure?

Methods included from Suffix

#allow_suffix?, #append_suffix, #random_suffix, #remove_suffix, #stack_name_suffix

Methods included from Lono::Conventions

#template_param_convention

Methods included from Blueprint::Root

#bundler_groups, #find_blueprint_root, #require_bundle_gems, #set_blueprint_root

Methods included from AwsServices

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

Methods included from AwsServices::Util

#find_stack, #rollback_complete?, #stack_exists?, #testing_update?

Constructor Details

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

Instance Method Details

#diffObject



64
65
66
# File 'lib/lono/cfn/update.rb', line 64

def diff
  @diff ||= Lono::Cfn::Diff.new(@stack_name, @options.merge(mute_params: true, mute_using: true))
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



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/lono/cfn/update.rb', line 46

def standard_update(params)
  params = {
    stack_name: @stack_name,
    parameters: params,
    capabilities: capabilities, # ["CAPABILITY_IAM", "CAPABILITY_NAMED_IAM"]
    disable_rollback: !@options[:rollback],
  }
  params[:tags] = tags unless tags.empty?
  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



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

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

  deleted = delete_rollback_stack
  if deleted
    Create.new(@stack_name, @options).create_stack(params)
    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(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