Sha256: 4b55da9546373851521d80a00dbbee7077d213dd05f6415376fe3e43e07f1d18

Contents?: true

Size: 1.8 KB

Versions: 13

Compression:

Stored size: 1.8 KB

Contents

class Lono::Cfn::Update < Lono::Cfn::Base
  # save_stack is the interface method
  def save_stack(params)
    update_stack(params)
  end

  # aws cloudformation update-stack --stack-name prod-hi-123456789 --parameters file://output/params/prod-hi-123456789.json --template-body file://output/prod-hi.json
  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

  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

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

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

  def change_set_update
    preview.execute_change_set
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
lono-3.5.0 lib/lono/cfn/update.rb
lono-3.4.1 lib/lono/cfn/update.rb
lono-3.4.0 lib/lono/cfn/update.rb
lono-3.3.4 lib/lono/cfn/update.rb
lono-3.3.2 lib/lono/cfn/update.rb
lono-3.3.0 lib/lono/cfn/update.rb
lono-3.2.1 lib/lono/cfn/update.rb
lono-3.2.0 lib/lono/cfn/update.rb
lono-3.1.3 lib/lono/cfn/update.rb
lono-3.1.2 lib/lono/cfn/update.rb
lono-3.1.1 lib/lono/cfn/update.rb
lono-3.0.1 lib/lono/cfn/update.rb
lono-3.0.0 lib/lono/cfn/update.rb