Sha256: 42de7256e0c6889ec97642cc340715cc9f26572de3a8b4550d770232458f252c

Contents?: true

Size: 1.71 KB

Versions: 4

Compression:

Stored size: 1.71 KB

Contents

module LonoCfn
  class Update < 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)
      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
        preview_changes if @options[:preview]
        are_you_sure?(:update)

        if @options[:change_set] # defaults to this
          message << " via change set: #{plan.change_set_name}"
          change_set_update
        else
          standard_update(params)
        end
      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: ["CAPABILITY_IAM"]
        )
      rescue Aws::CloudFormation::Errors::ValidationError => e
        puts "ERROR: #{e.message}".red
        error = true
      end
    end

    def plan
      return @plan if @plan
      @plan = Plan.new(@stack_name, @options.merge(lono: false, mute_params: true))
      @plan.setup
      @plan
    end

    def preview_changes
      plan.preview_change_set
    end

    def change_set_update
      plan.execute_change_set
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lono-cfn-1.0.4 lib/lono-cfn/update.rb
lono-cfn-1.0.2 lib/lono_cfn/update.rb
lono-cfn-1.0.1 lib/lono_cfn/update.rb
lono-cfn-1.0.0 lib/lono_cfn/update.rb