Class: Bora::Stack
- Inherits:
-
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.
9
10
11
12
13
|
# File 'lib/bora/stack.rb', line 9
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
79
80
81
|
# File 'lib/bora/stack.rb', line 79
def method_missing(sym, *args, &block)
underlying_stack ? underlying_stack.send(sym, *args, &block) : nil
end
|
Instance Method Details
#create(options, &block) ⇒ Object
15
16
17
|
# File 'lib/bora/stack.rb', line 15
def create(options, &block)
call_cfn_action(:create, options, &block)
end
|
#create_or_update(options, &block) ⇒ Object
23
24
25
|
# File 'lib/bora/stack.rb', line 23
def create_or_update(options, &block)
exists? ? update(options, &block) : create(options, &block)
end
|
#delete(&block) ⇒ Object
32
33
34
|
# File 'lib/bora/stack.rb', line 32
def delete(&block)
call_cfn_action(:delete, &block)
end
|
#diff(options) ⇒ Object
59
60
61
|
# File 'lib/bora/stack.rb', line 59
def diff(options)
Diffy::Diff.new(template, new_template(options))
end
|
#events ⇒ Object
36
37
38
39
40
|
# File 'lib/bora/stack.rb', line 36
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
71
72
73
|
# File 'lib/bora/stack.rb', line 71
def exists?
status.exists?
end
|
#new_template(options, pretty = true) ⇒ Object
49
50
51
52
53
54
55
56
57
|
# File 'lib/bora/stack.rb', line 49
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
|
#recreate(options, &block) ⇒ Object
27
28
29
30
|
# File 'lib/bora/stack.rb', line 27
def recreate(options, &block)
delete(&block) if exists?
create(options, &block) if !exists?
end
|
#status ⇒ Object
67
68
69
|
# File 'lib/bora/stack.rb', line 67
def status
StackStatus.new(underlying_stack)
end
|
#template(pretty = true) ⇒ Object
42
43
44
45
46
47
|
# File 'lib/bora/stack.rb', line 42
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
19
20
21
|
# File 'lib/bora/stack.rb', line 19
def update(options, &block)
call_cfn_action(:update, options, &block)
end
|
#validate(options) ⇒ Object
63
64
65
|
# File 'lib/bora/stack.rb', line 63
def validate(options)
@cfn.validate_template(options.select { |k| [:template_body, :template_url].include?(k) })
end
|