Class: Stackup::Stack
- Inherits:
-
Object
- Object
- Stackup::Stack
- Defined in:
- lib/stackup/stack.rb
Overview
An abstraction of a CloudFormation stack.
Constant Summary collapse
- ALMOST_DEAD_STATUSES =
%w(CREATE_FAILED ROLLBACK_COMPLETE)
Instance Attribute Summary collapse
-
#cf_client ⇒ Object
readonly
Returns the value of attribute cf_client.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#watcher ⇒ Object
readonly
Returns the value of attribute watcher.
Instance Method Summary collapse
-
#cancel_update ⇒ Symbol
Cancel update in-progress.
-
#create_or_update(options) ⇒ Symbol
(also: #up)
Create or update the stack.
-
#delete ⇒ Symbol
(also: #down)
Delete the stack.
-
#exists? ⇒ boolean
True iff the stack exists.
-
#initialize(name, client = {}, options = {}) ⇒ Stack
constructor
A new instance of Stack.
-
#on_event(event_handler = nil, &block) ⇒ Object
Register a handler for reporting of stack events.
-
#outputs ⇒ Hash<String, String>
Get stack outputs.
-
#status ⇒ String
The current stack status.
Constructor Details
#initialize(name, client = {}, options = {}) ⇒ Stack
Returns a new instance of Stack.
12 13 14 15 16 17 18 19 |
# File 'lib/stackup/stack.rb', line 12 def initialize(name, client = {}, = {}) client = Aws::CloudFormation::Client.new(client) if client.is_a?(Hash) @name = name @cf_client = client .each do |key, value| public_send("#{key}=", value) end end |
Instance Attribute Details
#cf_client ⇒ Object (readonly)
Returns the value of attribute cf_client.
21 22 23 |
# File 'lib/stackup/stack.rb', line 21 def cf_client @cf_client end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
21 22 23 |
# File 'lib/stackup/stack.rb', line 21 def name @name end |
#watcher ⇒ Object (readonly)
Returns the value of attribute watcher.
21 22 23 |
# File 'lib/stackup/stack.rb', line 21 def watcher @watcher end |
Instance Method Details
#cancel_update ⇒ Symbol
Cancel update in-progress.
99 100 101 102 103 104 105 106 107 |
# File 'lib/stackup/stack.rb', line 99 def cancel_update status = modify_stack do cf_stack.cancel_update end fail StackUpdateError, "update cancel failed" unless status =~ /_COMPLETE$/ :update_cancelled rescue InvalidStateError nil end |
#create_or_update(options) ⇒ Symbol Also known as: up
Create or update the stack.
57 58 59 60 61 62 63 64 |
# File 'lib/stackup/stack.rb', line 57 def create_or_update() = .dup [:capabilities] ||= ["CAPABILITY_IAM"] delete if ALMOST_DEAD_STATUSES.include?(status) update() rescue NoSuchStack create() end |
#delete ⇒ Symbol Also known as: down
Delete the stack.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/stackup/stack.rb', line 77 def delete begin @stack_id = cf_stack.stack_id rescue NoSuchStack return nil end status = modify_stack do cf_stack.delete end fail StackUpdateError, "stack delete failed" unless status == "DELETE_COMPLETE" :deleted ensure @stack_id = nil end |
#exists? ⇒ boolean
Returns true iff the stack exists.
41 42 43 44 45 46 |
# File 'lib/stackup/stack.rb', line 41 def exists? status true rescue NoSuchStack false end |
#on_event(event_handler = nil, &block) ⇒ Object
Register a handler for reporting of stack events
26 27 28 29 30 |
# File 'lib/stackup/stack.rb', line 26 def on_event(event_handler = nil, &block) event_handler ||= block fail ArgumentError, "no event_handler provided" if event_handler.nil? @event_handler = event_handler end |
#outputs ⇒ Hash<String, String>
Get stack outputs.
115 116 117 118 119 120 121 |
# File 'lib/stackup/stack.rb', line 115 def outputs {}.tap do |h| cf_stack.outputs.each do |output| h[output.output_key] = output.output_value end end end |
#status ⇒ String
Returns the current stack status.
35 36 37 |
# File 'lib/stackup/stack.rb', line 35 def status cf_stack.stack_status end |