class CfnStatus::RollbackStack

Attributes

cfn[R]
status[R]

Public Class Methods

handle!(stack_name, options={}) click to toggle source
# File lib/cfn_status/rollback_stack.rb, line 3
def self.handle!(stack_name, options={})
  new(stack_name, options).run
end
new(stack_name, options={}) click to toggle source
# File lib/cfn_status/rollback_stack.rb, line 8
def initialize(stack_name, options={})
  @stack_name = stack_name
  @cfn = options[:cfn]
  @status = CfnStatus.new(@stack_name, cfn: @cfn)
end

Public Instance Methods

find_stack(stack_name) click to toggle source
# File lib/cfn_status/rollback_stack.rb, line 29
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
rollback_complete?(stack) click to toggle source
# File lib/cfn_status/rollback_stack.rb, line 25
def rollback_complete?(stack)
  stack.stack_status == 'ROLLBACK_COMPLETE'
end
run() click to toggle source
# File lib/cfn_status/rollback_stack.rb, line 14
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