Class: CfnStatus::RollbackStack
- Inherits:
-
Object
- Object
- CfnStatus::RollbackStack
- Defined in:
- lib/cfn_status/rollback_stack.rb
Instance Attribute Summary collapse
-
#cfn ⇒ Object
readonly
Returns the value of attribute cfn.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
- #find_stack(stack_name) ⇒ Object
-
#initialize(stack_name, options = {}) ⇒ RollbackStack
constructor
A new instance of RollbackStack.
- #rollback_complete?(stack) ⇒ Boolean
- #run ⇒ Object
Constructor Details
#initialize(stack_name, options = {}) ⇒ RollbackStack
Returns a new instance of RollbackStack.
8 9 10 11 12 |
# File 'lib/cfn_status/rollback_stack.rb', line 8 def initialize(stack_name, ={}) @stack_name = stack_name @cfn = [:cfn] @status = CfnStatus.new(@stack_name, cfn: @cfn) end |
Instance Attribute Details
#cfn ⇒ Object (readonly)
Returns the value of attribute cfn.
7 8 9 |
# File 'lib/cfn_status/rollback_stack.rb', line 7 def cfn @cfn end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
7 8 9 |
# File 'lib/cfn_status/rollback_stack.rb', line 7 def status @status end |
Class Method Details
.handle!(stack_name, options = {}) ⇒ Object
3 4 5 |
# File 'lib/cfn_status/rollback_stack.rb', line 3 def self.handle!(stack_name, ={}) new(stack_name, ).run end |
Instance Method Details
#find_stack(stack_name) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cfn_status/rollback_stack.rb', line 29 def find_stack(stack_name) return if ENV['CFN_STATUS_TEST'] resp = cfn.describe_stacks(stack_name: stack_name) resp.stacks.first rescue Aws::CloudFormation::Errors::ValidationError => e # example: Stack with id demo-web does not exist if e. =~ /Stack with/ && e. =~ /does not exist/ nil else raise end end |
#rollback_complete?(stack) ⇒ Boolean
25 26 27 |
# File 'lib/cfn_status/rollback_stack.rb', line 25 def rollback_complete?(stack) stack.stack_status == 'ROLLBACK_COMPLETE' end |
#run ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/cfn_status/rollback_stack.rb', line 14 def run @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 |