Sha256: 69de6f3f3fe9751268667314e3235ec7bd5c613c8d6c8c43e3409e8daf3509bf

Contents?: true

Size: 994 Bytes

Versions: 7

Compression:

Stored size: 994 Bytes

Contents

require "aws-sdk-cloudformation"

module Cody
  class Stack
    include Cody::AwsServices

    def initialize(options)
      @options = options
      @project_name = @options[:project_name] || inferred_project_name
      @stack_name = normalize_stack_name(options[:stack_name] || inferred_stack_name(@project_name))
    end

    def run
      handle_rollback_completed!
      if stack_exists?(@stack_name)
        Update.new(@options).run
      else
        Create.new(@options).run
      end
    end

  private
    def handle_rollback_completed!
      @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
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
cody-1.0.6 lib/cody/stack.rb
cody-1.0.5 lib/cody/stack.rb
cody-1.0.4 lib/cody/stack.rb
cody-1.0.3 lib/cody/stack.rb
cody-1.0.2 lib/cody/stack.rb
cody-1.0.1 lib/cody/stack.rb
cody-1.0.0 lib/cody/stack.rb