Class: Stackup::Stack
- Inherits:
-
Object
- Object
- Stackup::Stack
- Defined in:
- lib/stackup/stack.rb
Constant Summary collapse
- SUCESS_STATES =
["CREATE_COMPLETE", "UPDATE_COMPLETE"]
- FAILURE_STATES =
["CREATE_FAILED", "DELETE_FAILED", "UPDATE_ROLLBACK_FAILED", "ROLLBACK_FAILED", "ROLLBACK_COMPLETE","ROLLBACK_FAILED","UPDATE_ROLLBACK_COMPLETE","UPDATE_ROLLBACK_FAILED"]
- END_STATES =
SUCESS_STATES + FAILURE_STATES
Instance Attribute Summary collapse
-
#cf ⇒ Object
readonly
Returns the value of attribute cf.
-
#monitor ⇒ Object
readonly
Returns the value of attribute monitor.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
- #create ⇒ Object
- #deployed? ⇒ Boolean
- #display_events ⇒ Object
-
#initialize(name, template) ⇒ Stack
constructor
A new instance of Stack.
- #valid? ⇒ Boolean
Constructor Details
#initialize(name, template) ⇒ Stack
Returns a new instance of Stack.
10 11 12 13 14 15 16 |
# File 'lib/stackup/stack.rb', line 10 def initialize(name, template) @cf = Aws::CloudFormation::Client.new @stack = Aws::CloudFormation::Stack.new(name: name, client: cf) @monitor = Stackup::Monitor.new(@stack) @template = template @name = name end |
Instance Attribute Details
#cf ⇒ Object (readonly)
Returns the value of attribute cf.
5 6 7 |
# File 'lib/stackup/stack.rb', line 5 def cf @cf end |
#monitor ⇒ Object (readonly)
Returns the value of attribute monitor.
5 6 7 |
# File 'lib/stackup/stack.rb', line 5 def monitor @monitor end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/stackup/stack.rb', line 5 def name @name end |
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
5 6 7 |
# File 'lib/stackup/stack.rb', line 5 def stack @stack end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
5 6 7 |
# File 'lib/stackup/stack.rb', line 5 def template @template end |
Instance Method Details
#create ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/stackup/stack.rb', line 18 def create response = cf.create_stack({ stack_name: name, template_body: template, disable_rollback: true }) !response[:stack_id].nil? stack.wait_until(max_attempts: 1000, delay: 10) { |resource| display_events ; END_STATES.include?(resource.stack_status) } end |
#deployed? ⇒ Boolean
36 37 38 39 40 |
# File 'lib/stackup/stack.rb', line 36 def deployed? !stack.stack_status.nil? rescue Aws::CloudFormation::Errors::ValidationError => e false end |
#display_events ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/stackup/stack.rb', line 28 def display_events monitor.new_events.each do |e| ts = e..localtime.strftime("%H:%M:%S") fields = [e.logical_resource_id, e.resource_status, e.resource_status_reason] puts("[#{ts}] #{fields.compact.join(' - ')}") end end |
#valid? ⇒ Boolean
42 43 44 45 |
# File 'lib/stackup/stack.rb', line 42 def valid? response = cf.validate_template(template) response[:code].nil? end |