Class: Lono::Cfn::Update

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

Instance Method Summary collapse

Methods inherited from Base

#capabilities, #command_with_iam, #continue_update_rollback, #continue_update_rollback_sure?, #delete_rollback_stack, #exit_unless_updatable!, #generate_all, #notification_arns, #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



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

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

#param_previewObject



66
67
68
# File 'lib/lono/cfn/update.rb', line 66

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

#save(parameters) ⇒ Object

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



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

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

  deleted = delete_rollback_stack
  if deleted
    Create.new(@options).save(parameters)
    return
  end

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

  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
  changeset_preview = Lono::Cfn::Preview::Changeset.new(options)

  param_preview.run if @options[:param_preview]
  codediff_preview.run if @options[:codediff_preview]
  changeset_preview.run if @options[:changeset_preview]
  sure?("Are you sure you want to update the #{@stack} stack?")

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

#standard_update(parameters) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/lono/cfn/update.rb', line 42

def standard_update(parameters)
  options = {
    stack_name: @stack,
    parameters: parameters,
    capabilities: capabilities, # ["CAPABILITY_IAM", "CAPABILITY_NAMED_IAM"]
    disable_rollback: !@options[:rollback],
  }
  options[:notification_arns] = notification_arns if notification_arns
  options[:tags] = tags unless tags.empty?
  set_template_url!(options)
  show_options(options, "cfn.update_stack")
  begin
    cfn.update_stack(options)
  rescue Aws::CloudFormation::Errors::ValidationError => e
    puts "ERROR: #{e.message}".color(:red)
    false
  end
end