Sha256: c41f5e6cce762f1acc0364ee5e8a71212b57c6cfe34ffaf992191b177ae90569

Contents?: true

Size: 1.72 KB

Versions: 7

Compression:

Stored size: 1.72 KB

Contents

class Lono::Sets
  class Delete
    include Lono::AwsServices
    include Lono::Sets::Summarize
    include Lono::Utils::Sure

    def initialize(options={})
      @options = options
      @stack = options.delete(:stack)
    end

    def run
      message = "Deleting #{@stack} stack set."
      if @options[:noop]
        puts "NOOP #{message}"
      else
        desc =<<~EOL
          Be sure that the emptied StackSet instances is emptied first.
          You can empty it with a separate command: lono sets instances delete #{@stack} --all
          This command will only delete the StackSet itself after it's been emptied.
        EOL
        sure?("Are you sure you want to delete the #{@stack} stack set?", desc)

        if stack_set_exists?(@stack)
          cfn.delete_stack_set(stack_set_name: @stack) # resp is an Empty structure, so much get operation_id from status
          puts message
        else
          puts "#{@stack.inspect} stack set does not exist".color(:red)
          return
        end
      end

      return true if @options[:noop] || !@options[:wait]

      status = Status.new(@options)
      success = status.wait
      operation_id = status.operation_id # getting operation_id from status because cfn.delete_stack_set resp is an Empty structure
      summarize(operation_id)
      exit 1 unless success

    rescue Aws::CloudFormation::Errors::StackSetNotEmptyException => e
      puts "ERROR: #{e.class}: #{e.message}".color(:red)
      puts <<~EOL
        The stack set must be empty before deleting. Cannot delete stack set until all stack instances are first
        deleted. If you want to delete all stack instances you can use:

            lono sets instances delete #{@stack} --all

      EOL
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
lono-7.4.11 lib/lono/sets/delete.rb
lono-7.4.10 lib/lono/sets/delete.rb
lono-7.4.9 lib/lono/sets/delete.rb
lono-7.4.8 lib/lono/sets/delete.rb
lono-7.4.7 lib/lono/sets/delete.rb
lono-7.4.6 lib/lono/sets/delete.rb
lono-7.4.5 lib/lono/sets/delete.rb