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
46
47
48
49
50
# File 'lib/lono/sets/delete.rb', line 12

def run
  message = "Deleting #{@stack} stack set."
  if @options[:noop]
    puts "NOOP #{message}"
  else
    desc ="      Be sure that the emptied StackSet instances is emptied first.\n      You can empty it with a separate command: lono sets instances delete \#{@stack} --all\n      This command will only delete the StackSet itself after it's been emptied.\n    EOL\n    sure?(\"Are you sure you want to delete the \#{@stack} stack set?\", desc)\n\n    if stack_set_exists?(@stack)\n      cfn.delete_stack_set(stack_set_name: @stack) # resp is an Empty structure, so much get operation_id from status\n      puts message\n    else\n      puts \"\#{@stack.inspect} stack set does not exist\".color(:red)\n      return\n    end\n  end\n\n  return true if @options[:noop] || !@options[:wait]\n\n  status = Status.new(@options)\n  success = status.wait\n  operation_id = status.operation_id # getting operation_id from status because cfn.delete_stack_set resp is an Empty structure\n  summarize(operation_id)\n  exit 1 unless success\n\nrescue Aws::CloudFormation::Errors::StackSetNotEmptyException => e\n  puts \"ERROR: \#{e.class}: \#{e.message}\".color(:red)\n  puts <<~EOL\n    The stack set must be empty before deleting. Cannot delete stack set until all stack instances are first\n    deleted. If you want to delete all stack instances you can use:\n\n        lono sets instances delete \#{@stack} --all\n\n  EOL\nend\n"