Class: Bora::Cfn::Stack
- Inherits:
-
Object
show all
- Defined in:
- lib/bora/cfn/stack.rb
Constant Summary
collapse
- NO_UPDATE_MESSAGE =
"No updates are to be performed"
Instance Method Summary
collapse
Constructor Details
#initialize(stack_name, region = nil) ⇒ 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
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
97
98
99
|
# File 'lib/bora/cfn/stack.rb', line 97
def method_missing(sym, *args, &block)
underlying_stack ? underlying_stack.send(sym, *args, &block) : nil
end
|
Instance Method Details
#create(options, &block) ⇒ Object
21
22
23
|
# File 'lib/bora/cfn/stack.rb', line 21
def create(options, &block)
call_cfn_action(:create, options, &block)
end
|
#create_or_update(options, &block) ⇒ Object
29
30
31
|
# File 'lib/bora/cfn/stack.rb', line 29
def create_or_update(options, &block)
exists? ? update(options, &block) : create(options, &block)
end
|
#delete(&block) ⇒ Object
38
39
40
|
# File 'lib/bora/cfn/stack.rb', line 38
def delete(&block)
call_cfn_action(:delete, &block)
end
|
#diff(options) ⇒ Object
71
72
73
|
# File 'lib/bora/cfn/stack.rb', line 71
def diff(options)
Diffy::Diff.new(template, new_template(options))
end
|
#events ⇒ Object
42
43
44
45
46
|
# File 'lib/bora/cfn/stack.rb', line 42
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
83
84
85
|
# File 'lib/bora/cfn/stack.rb', line 83
def exists?
status.exists?
end
|
#new_template(options, pretty = true) ⇒ Object
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/bora/cfn/stack.rb', line 60
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
|
#outputs ⇒ Object
48
49
50
51
|
# File 'lib/bora/cfn/stack.rb', line 48
def outputs
return if !exists?
underlying_stack.outputs.map { |output| Output.new(output) }
end
|
#recreate(options, &block) ⇒ Object
33
34
35
36
|
# File 'lib/bora/cfn/stack.rb', line 33
def recreate(options, &block)
delete(&block) if exists?
create(options, &block) if !exists?
end
|
#status ⇒ Object
79
80
81
|
# File 'lib/bora/cfn/stack.rb', line 79
def status
StackStatus.new(underlying_stack)
end
|
#template(pretty = true) ⇒ Object
53
54
55
56
57
58
|
# File 'lib/bora/cfn/stack.rb', line 53
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
25
26
27
|
# File 'lib/bora/cfn/stack.rb', line 25
def update(options, &block)
call_cfn_action(:update, options, &block)
end
|
#validate(options) ⇒ Object
75
76
77
|
# File 'lib/bora/cfn/stack.rb', line 75
def validate(options)
cloudformation.validate_template(resolve_options(options).select { |k| [:template_body, :template_url].include?(k) })
end
|