Class: Bora::Stack

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

Constant Summary collapse

NO_UPDATE_MESSAGE =
"No updates are to be performed"

Instance Method Summary collapse

Constructor Details

#initialize(stack_name) ⇒ Stack

Returns a new instance of Stack.



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

def initialize(stack_name)
  @stack_name = stack_name
  @processed_events = Set.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object (private)



92
93
94
# File 'lib/bora/stack.rb', line 92

def method_missing(sym, *args, &block)
  underlying_stack ? underlying_stack.send(sym, *args, &block) : nil
end

Instance Method Details

#create(options, &block) ⇒ Object



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

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

#create_or_update(options, &block) ⇒ Object



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

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

#delete(&block) ⇒ Object



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

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

#diff(options) ⇒ Object



68
69
70
# File 'lib/bora/stack.rb', line 68

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

#eventsObject



39
40
41
42
43
# File 'lib/bora/stack.rb', line 39

def events
  return if !exists?
  events = cloudformation.describe_stack_events({stack_name: underlying_stack.stack_id}).stack_events
  events.reverse.map { |e| Event.new(e) }
end

#exists?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/bora/stack.rb', line 80

def exists?
  status.exists?
end

#new_template(options, pretty = true) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/bora/stack.rb', line 57

def new_template(options, pretty = true)
  options = resolve_options(options, true)
  template = options[:template_body]
  if template
    template = JSON.pretty_generate(JSON.parse(template)) if pretty
    template
  else
    raise "new_template not yet implemented for URL #{options[:template_url]}"
  end
end

#outputsObject



45
46
47
48
# File 'lib/bora/stack.rb', line 45

def outputs
  return if !exists?
  underlying_stack.outputs.map { |output| Output.new(output) }
end

#recreate(options, &block) ⇒ Object



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

def recreate(options, &block)
  delete(&block) if exists?
  create(options, &block) if !exists?
end

#statusObject



76
77
78
# File 'lib/bora/stack.rb', line 76

def status
  StackStatus.new(underlying_stack)
end

#template(pretty = true) ⇒ Object



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

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

#update(options, &block) ⇒ Object



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

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

#validate(options) ⇒ Object



72
73
74
# File 'lib/bora/stack.rb', line 72

def validate(options)
  cloudformation.validate_template(resolve_options(options).select { |k| [:template_body, :template_url].include?(k) })
end