Class: Bora::Stack

Inherits:
Object
  • Object
show all
Defined in:
lib/bora/stack.rb

Instance Method Summary collapse

Constructor Details

#initialize(stack_name) ⇒ Stack

Returns a new instance of Stack.



7
8
9
10
11
# File 'lib/bora/stack.rb', line 7

def initialize(stack_name)
  @stack_name = stack_name
  @cfn = Aws::CloudFormation::Client.new
  @processed_events = Set.new
end

Instance Method Details

#create(options, &block) ⇒ Object



13
14
15
# File 'lib/bora/stack.rb', line 13

def create(options, &block)
  call_cfn_action(:create, options, &block)
end

#create_or_update(options, &block) ⇒ Object



21
22
23
# File 'lib/bora/stack.rb', line 21

def create_or_update(options, &block)
  exists? ? update(options, &block) : create(options, &block)
end

#delete(&block) ⇒ Object



25
26
27
# File 'lib/bora/stack.rb', line 25

def delete(&block)
  call_cfn_action(:delete, &block)
end

#diff(options) ⇒ Object



52
53
54
# File 'lib/bora/stack.rb', line 52

def diff(options)
  Diffy::Diff.new(template, new_template(options))
end

#eventsObject



29
30
31
32
33
# File 'lib/bora/stack.rb', line 29

def events
  return [] if !underlying_stack
  events = @cfn.describe_stack_events({stack_name: underlying_stack.stack_id}).stack_events
  events.reverse.map { |e| Event.new(e) }
end

#exists?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/bora/stack.rb', line 56

def exists?
  underlying_stack && underlying_stack.stack_status != 'DELETE_COMPLETE'
end

#new_template(options, pretty = true) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/bora/stack.rb', line 42

def new_template(options, pretty = true)
  if options[:template_body]
    template = options[:template_body]
    template = JSON.pretty_generate(JSON.parse(template)) if pretty
    template
  else
    raise Exception("new_template not yet implemented for template_url stack option")
  end
end

#template(pretty = true) ⇒ Object



35
36
37
38
39
40
# File 'lib/bora/stack.rb', line 35

def template(pretty = true)
  return if !exists?
  template = @cfn.get_template({stack_name: @stack_name}).template_body
  template = JSON.pretty_generate(JSON.parse(template)) if pretty
  template
end

#update(options, &block) ⇒ Object



17
18
19
# File 'lib/bora/stack.rb', line 17

def update(options, &block)
  call_cfn_action(:update, options, &block)
end