Sha256: 28cba8e2d5630d427f982253ffdc1eee3499b045ccd4f83867030a2259ed4207

Contents?: true

Size: 1.25 KB

Versions: 5

Compression:

Stored size: 1.25 KB

Contents

class Stack

  def initialize(args)
    @aws    = args[:aws]
    @name   = args[:name]
    @region = @aws.region
    @logger = Roark.logger
  end

  def create(args)
    @logger.info "Creating Cloud Formation stack '#{@name}' in '#{@region}'."
    create_stack.create :name       => @name,
                        :parameters => args[:parameters],
                        :template   => args[:template]
  end

  def destroy
    @logger.info "Destroying Cloud Formation stack '#{@name}'."
    destroy_stack.destroy @name
  end

  def exists?
    stack_status.exists? @name
  end

  def in_progress?
    status =~ /^CREATE_IN_PROGRESS$/
  end

  def success?
    status =~ /^CREATE_COMPLETE$/
  end

  def instance_id
    outputs.find {|o| o.key == 'InstanceId'}.value
  end

  private

  def status
    stack_status.status @name
  end

  def outputs
    stack_outputs.outputs @name
  end

  def create_stack
    @create_stack ||= Roark::Aws::CloudFormation::CreateStack.new @aws
  end

  def destroy_stack
    @destroy_stack ||= Roark::Aws::CloudFormation::DestroyStack.new @aws
  end

  def stack_outputs
    @stack_outputs ||= Roark::Aws::CloudFormation::StackOutputs.new @aws
  end

  def stack_status
    @stack_status ||= Roark::Aws::CloudFormation::StackStatus.new @aws
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
roark-0.2.2 lib/roark/stack.rb
roark-0.2.1 lib/roark/stack.rb
roark-0.2.0 lib/roark/stack.rb
roark-0.1.0 lib/roark/stack.rb
roark-0.0.1 lib/roark/stack.rb