Sha256: 912de2efa883fe36122930361c6cc8a08d728e35da555aa312553540f49d4720

Contents?: true

Size: 1.14 KB

Versions: 10

Compression:

Stored size: 1.14 KB

Contents

class CfnStatus
  class RollbackStack
    def self.handle!(stack_name, options={})
      new(stack_name, options).run
    end

    attr_reader :status, :cfn
    def initialize(stack_name, options={})
      @stack_name = stack_name
      @cfn = options[:cfn]
      @status = CfnStatus.new(@stack_name, cfn: @cfn)
    end

    def run
      @stack = find_stack(@stack_name)
      if @stack && rollback_complete?(@stack)
        puts "Existing stack in ROLLBACK_COMPLETE state. Deleting stack before continuing."
        cfn.delete_stack(stack_name: @stack_name)
        status.wait
        status.reset
        @stack = nil # at this point stack has been deleted
      end
    end

    def rollback_complete?(stack)
      stack.stack_status == 'ROLLBACK_COMPLETE'
    end

    def find_stack(stack_name)
      return if ENV['CFN_STATUS_TEST']
      resp = cfn.describe_stacks(stack_name: stack_name)
      resp.stacks.first
    rescue Aws::CloudFormation::Errors::ValidationError => e
      # example: Stack with id demo-web does not exist
      if e.message =~ /Stack with/ && e.message =~ /does not exist/
        nil
      else
        raise
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
cfn-status-0.6.1 lib/cfn_status/rollback_stack.rb
cfn-status-0.6.0 lib/cfn_status/rollback_stack.rb
cfn-status-0.5.0 lib/cfn_status/rollback_stack.rb
cfn-status-0.4.6 lib/cfn_status/rollback_stack.rb
cfn-status-0.4.5 lib/cfn_status/rollback_stack.rb
cfn-status-0.4.4 lib/cfn_status/rollback_stack.rb
cfn-status-0.4.3 lib/cfn_status/rollback_stack.rb
cfn-status-0.4.2 lib/cfn_status/rollback_stack.rb
cfn-status-0.4.1 lib/cfn_status/rollback_stack.rb
cfn-status-0.4.0 lib/cfn_status/rollback_stack.rb