Class: Lono::Sets::Delete

Inherits:
Object
  • Object
show all
Includes:
AwsServices, Summarize, Utils::Sure
Defined in:
lib/lono/sets/delete.rb

Instance Method Summary collapse

Methods included from Utils::Sure

#sure?

Methods included from Summarize

#summarize

Methods included from AwsServices

#cfn, #ec2, #iam, #s3, #s3_presigner, #s3_resource, #sts

Methods included from AwsServices::Helper

#rollback_complete?, #testing_update?

Methods included from AwsServices::StackSet

#find_stack_set, #stack_set_exists?

Methods included from AwsServices::Stack

#find_stack, #stack_exists?

Constructor Details

#initialize(options = {}) ⇒ Delete

Returns a new instance of Delete.



7
8
9
10
# File 'lib/lono/sets/delete.rb', line 7

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

Instance Method Details

#runObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/lono/sets/delete.rb', line 12

def run
  message = "Deleting #{@stack} stack set."
  if @options[:noop]
    puts "NOOP #{message}"
  else
    sure?("Are you sure you want to delete the #{@stack} stack set?", "Be sure that it emptied of stack instances first.")

    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