Class: Bora::Stack
- Inherits:
-
Object
show all
- Defined in:
- lib/bora/stack.rb
Instance Method Summary
collapse
Constructor Details
#initialize(stack_name) ⇒ Stack
10
11
12
13
14
|
# File 'lib/bora/stack.rb', line 10
def initialize(stack_name)
@stack_name = stack_name
@cfn = Aws::CloudFormation::Client.new
@processed_events = Set.new
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
85
86
87
|
# File 'lib/bora/stack.rb', line 85
def method_missing(sym, *args, &block)
underlying_stack ? underlying_stack.send(sym, *args, &block) : nil
end
|
Instance Method Details
#create(options, &block) ⇒ Object
16
17
18
|
# File 'lib/bora/stack.rb', line 16
def create(options, &block)
call_cfn_action(:create, options, &block)
end
|
#create_or_update(options, &block) ⇒ Object
24
25
26
|
# File 'lib/bora/stack.rb', line 24
def create_or_update(options, &block)
exists? ? update(options, &block) : create(options, &block)
end
|
#delete(&block) ⇒ Object
33
34
35
|
# File 'lib/bora/stack.rb', line 33
def delete(&block)
call_cfn_action(:delete, &block)
end
|
#diff(options) ⇒ Object
65
66
67
|
# File 'lib/bora/stack.rb', line 65
def diff(options)
Diffy::Diff.new(template, new_template(options))
end
|
#events ⇒ Object
37
38
39
40
41
|
# File 'lib/bora/stack.rb', line 37
def events
return if !exists?
events = @cfn.describe_stack_events({stack_name: underlying_stack.stack_id}).stack_events
events.reverse.map { |e| Event.new(e) }
end
|
#exists? ⇒ Boolean
77
78
79
|
# File 'lib/bora/stack.rb', line 77
def exists?
status.exists?
end
|
#new_template(options, pretty = true) ⇒ Object
55
56
57
58
59
60
61
62
63
|
# File 'lib/bora/stack.rb', line 55
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
|
#outputs ⇒ Object
43
44
45
46
|
# File 'lib/bora/stack.rb', line 43
def outputs
return if !exists?
underlying_stack.outputs.map { |output| Output.new(output) }
end
|
#recreate(options, &block) ⇒ Object
28
29
30
31
|
# File 'lib/bora/stack.rb', line 28
def recreate(options, &block)
delete(&block) if exists?
create(options, &block) if !exists?
end
|
#status ⇒ Object
73
74
75
|
# File 'lib/bora/stack.rb', line 73
def status
StackStatus.new(underlying_stack)
end
|
#template(pretty = true) ⇒ Object
48
49
50
51
52
53
|
# File 'lib/bora/stack.rb', line 48
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
20
21
22
|
# File 'lib/bora/stack.rb', line 20
def update(options, &block)
call_cfn_action(:update, options, &block)
end
|
#validate(options) ⇒ Object
69
70
71
|
# File 'lib/bora/stack.rb', line 69
def validate(options)
@cfn.validate_template(options.select { |k| [:template_body, :template_url].include?(k) })
end
|