Class: Bora::Cfn::Stack
- Inherits:
-
Object
- Object
- Bora::Cfn::Stack
- Defined in:
- lib/bora/cfn/stack.rb
Constant Summary collapse
- NO_UPDATE_MESSAGE =
'No updates are to be performed'.freeze
Instance Method Summary collapse
- #create(options, &block) ⇒ Object
- #create_change_set(change_set_name, options) ⇒ Object
- #create_or_update(options, &block) ⇒ Object
- #delete(&block) ⇒ Object
- #delete_change_set(change_set_name) ⇒ Object
- #describe_change_set(change_set_name) ⇒ Object
- #events ⇒ Object
- #execute_change_set(change_set_name, &block) ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(stack_name, region = nil) ⇒ Stack
constructor
A new instance of Stack.
- #list_change_sets ⇒ Object
- #outputs ⇒ Object
- #parameters ⇒ Object
- #recreate(options, &block) ⇒ Object
- #status ⇒ Object
- #template ⇒ Object
- #update(options, &block) ⇒ Object
- #validate(options) ⇒ Object
Constructor Details
#initialize(stack_name, region = nil) ⇒ Stack
Returns a new instance of Stack.
15 16 17 18 19 |
# File 'lib/bora/cfn/stack.rb', line 15 def initialize(stack_name, region = nil) @stack_name = stack_name @region = region @processed_events = Set.new end |
Instance Method Details
#create(options, &block) ⇒ Object
21 22 23 |
# File 'lib/bora/cfn/stack.rb', line 21 def create(, &block) call_cfn_action(:create_stack, , &block) end |
#create_change_set(change_set_name, options) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/bora/cfn/stack.rb', line 78 def create_change_set(change_set_name, ) = { stack_name: @stack_name, change_set_name: change_set_name } cloudformation.create_change_set(.merge()) loop do change_set = ChangeSet.new(cloudformation.describe_change_set()) return change_set if change_set.status_complete? sleep 5 end end |
#create_or_update(options, &block) ⇒ Object
32 33 34 |
# File 'lib/bora/cfn/stack.rb', line 32 def create_or_update(, &block) exists? ? update(, &block) : create(, &block) end |
#delete(&block) ⇒ Object
41 42 43 |
# File 'lib/bora/cfn/stack.rb', line 41 def delete(&block) call_cfn_action(:delete_stack, &block) end |
#delete_change_set(change_set_name) ⇒ Object
100 101 102 |
# File 'lib/bora/cfn/stack.rb', line 100 def delete_change_set(change_set_name) cloudformation.delete_change_set(stack_name: @stack_name, change_set_name: change_set_name) end |
#describe_change_set(change_set_name) ⇒ Object
96 97 98 |
# File 'lib/bora/cfn/stack.rb', line 96 def describe_change_set(change_set_name) ChangeSet.new(cloudformation.describe_change_set(stack_name: @stack_name, change_set_name: change_set_name)) end |
#events ⇒ Object
45 46 47 48 49 |
# File 'lib/bora/cfn/stack.rb', line 45 def events return unless exists? events = cloudformation.describe_stack_events(stack_name: .stack_id).stack_events events.reverse.map { |e| Event.new(e) } end |
#execute_change_set(change_set_name, &block) ⇒ Object
104 105 106 |
# File 'lib/bora/cfn/stack.rb', line 104 def execute_change_set(change_set_name, &block) call_cfn_action(:execute_change_set, { change_set_name: change_set_name }, &block) end |
#exists? ⇒ Boolean
74 75 76 |
# File 'lib/bora/cfn/stack.rb', line 74 def exists? status.exists? end |
#list_change_sets ⇒ Object
91 92 93 94 |
# File 'lib/bora/cfn/stack.rb', line 91 def list_change_sets cfn_change_sets = cloudformation.list_change_sets(stack_name: @stack_name) cfn_change_sets.summaries.map { |cs| ChangeSet.new(cs, true) } end |
#outputs ⇒ Object
51 52 53 54 |
# File 'lib/bora/cfn/stack.rb', line 51 def outputs return unless exists? .outputs.map { |output| Output.new(output) } end |
#parameters ⇒ Object
56 57 58 59 |
# File 'lib/bora/cfn/stack.rb', line 56 def parameters return unless exists? .parameters.map { |parameter| Parameter.new(parameter) } end |
#recreate(options, &block) ⇒ Object
36 37 38 39 |
# File 'lib/bora/cfn/stack.rb', line 36 def recreate(, &block) delete(&block) if exists? create(, &block) unless exists? end |
#status ⇒ Object
70 71 72 |
# File 'lib/bora/cfn/stack.rb', line 70 def status StackStatus.new() end |
#template ⇒ Object
61 62 63 64 |
# File 'lib/bora/cfn/stack.rb', line 61 def template return unless exists? cloudformation.get_template(stack_name: @stack_name).template_body end |
#update(options, &block) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/bora/cfn/stack.rb', line 25 def update(, &block) # Parameters that are not valid for the update_stack api = %i(on_failure disable_rollback) = .select { |key| !.include?(key) } call_cfn_action(:update_stack, , &block) end |
#validate(options) ⇒ Object
66 67 68 |
# File 'lib/bora/cfn/stack.rb', line 66 def validate() cloudformation.validate_template(.select { |k| [:template_body, :template_url].include?(k) }) end |