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) ⇒ Stack
Returns a new instance of Stack.
15
16
17
18
|
# File 'lib/bora/cfn/stack.rb', line 15
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
94
95
96
|
# File 'lib/bora/cfn/stack.rb', line 94
def method_missing(sym, *args, &block)
underlying_stack ? underlying_stack.send(sym, *args, &block) : nil
end
|
Instance Method Details
#create(options, &block) ⇒ Object
20
21
22
|
# File 'lib/bora/cfn/stack.rb', line 20
def create(options, &block)
call_cfn_action(:create, options, &block)
end
|
#create_or_update(options, &block) ⇒ Object
28
29
30
|
# File 'lib/bora/cfn/stack.rb', line 28
def create_or_update(options, &block)
exists? ? update(options, &block) : create(options, &block)
end
|
#delete(&block) ⇒ Object
37
38
39
|
# File 'lib/bora/cfn/stack.rb', line 37
def delete(&block)
call_cfn_action(:delete, &block)
end
|
#diff(options) ⇒ Object
70
71
72
|
# File 'lib/bora/cfn/stack.rb', line 70
def diff(options)
Diffy::Diff.new(template, new_template(options))
end
|
#events ⇒ Object
41
42
43
44
45
|
# File 'lib/bora/cfn/stack.rb', line 41
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
82
83
84
|
# File 'lib/bora/cfn/stack.rb', line 82
def exists?
status.exists?
end
|
#new_template(options, pretty = true) ⇒ Object
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/bora/cfn/stack.rb', line 59
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
47
48
49
50
|
# File 'lib/bora/cfn/stack.rb', line 47
def outputs
return if !exists?
underlying_stack.outputs.map { |output| Output.new(output) }
end
|
#recreate(options, &block) ⇒ Object
32
33
34
35
|
# File 'lib/bora/cfn/stack.rb', line 32
def recreate(options, &block)
delete(&block) if exists?
create(options, &block) if !exists?
end
|
#status ⇒ Object
78
79
80
|
# File 'lib/bora/cfn/stack.rb', line 78
def status
StackStatus.new(underlying_stack)
end
|
#template(pretty = true) ⇒ Object
52
53
54
55
56
57
|
# File 'lib/bora/cfn/stack.rb', line 52
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
24
25
26
|
# File 'lib/bora/cfn/stack.rb', line 24
def update(options, &block)
call_cfn_action(:update, options, &block)
end
|
#validate(options) ⇒ Object
74
75
76
|
# File 'lib/bora/cfn/stack.rb', line 74
def validate(options)
cloudformation.validate_template(resolve_options(options).select { |k| [:template_body, :template_url].include?(k) })
end
|