Class: Murk::Model::Stack
- Inherits:
-
Object
- Object
- Murk::Model::Stack
show all
- Includes:
- Murk, AWS
- Defined in:
- lib/murk/model/stack.rb
Constant Summary
Constants included
from Murk
DEFAULT_OPTIONS
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from AWS
#cloudformation
Methods included from Murk
config_dir, config_file, config_file=, configure, load, logger, #logger, logger=, options
Constructor Details
#initialize(name, env:, user:, template_filename: name + '.json') ⇒ Stack
Returns a new instance of Stack.
14
15
16
17
18
19
20
|
# File 'lib/murk/model/stack.rb', line 14
def initialize(name, env:, user:, template_filename: name + '.json')
@name = name
@env = env
@template = Template.new(template_filename)
@user = user
@parameters = []
end
|
Instance Attribute Details
#env ⇒ Object
Returns the value of attribute env.
12
13
14
|
# File 'lib/murk/model/stack.rb', line 12
def env
@env
end
|
#name ⇒ Object
Returns the value of attribute name.
12
13
14
|
# File 'lib/murk/model/stack.rb', line 12
def name
@name
end
|
#template ⇒ Object
Returns the value of attribute template.
12
13
14
|
# File 'lib/murk/model/stack.rb', line 12
def template
@template
end
|
#user ⇒ Object
Returns the value of attribute user.
12
13
14
|
# File 'lib/murk/model/stack.rb', line 12
def user
@user
end
|
Instance Method Details
#add_parameter(parameter) ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/murk/model/stack.rb', line 26
def add_parameter(parameter)
if @template.parameter?(parameter.key)
@parameters << parameter
else
fail StackError, "No such parameter '#{parameter.key}' for template '#{@template.filename}'"
end
end
|
#create_or_update ⇒ Object
38
39
40
41
|
# File 'lib/murk/model/stack.rb', line 38
def create_or_update
fail StackError, "Stack '#{@name}' is in failed state" if failed?
exists? ? update : create
end
|
#delete ⇒ Object
43
44
45
46
|
# File 'lib/murk/model/stack.rb', line 43
def delete
fail StackError "Stack #{@name} does not exist" unless exists?
cloudformation.delete_stack(stack_name: qualified_name)
end
|
#exists? ⇒ Boolean
48
49
50
|
# File 'lib/murk/model/stack.rb', line 48
def exists?
existing.any?
end
|
#failed? ⇒ Boolean
52
53
54
55
56
|
# File 'lib/murk/model/stack.rb', line 52
def failed?
existing.any? do |stack|
stack.stack_status =~ /FAILED/
end
end
|
#output(key) ⇒ Object
70
71
72
73
74
75
|
# File 'lib/murk/model/stack.rb', line 70
def output(key)
return unless exists?
outputs = cloudformation.describe_stacks(stack_name: qualified_name)[:stacks][0][:outputs]
output = outputs.find { |o| o.output_key == key.to_s }
output ? output.output_value : nil
end
|
#parameter_value(parameter_key) ⇒ Object
34
35
36
|
# File 'lib/murk/model/stack.rb', line 34
def parameter_value(parameter_key)
@parameters.find { |parameter| parameter.key == parameter_key }.resolve
end
|
#qualified_name ⇒ Object
62
63
64
65
66
67
68
|
# File 'lib/murk/model/stack.rb', line 62
def qualified_name
qualified_name = ''
if Murk.options[:stack_prefix]
qualified_name += Murk.options[:stack_prefix] + '-'
end
qualified_name + "#{@env}-#{@user}-#{@name}"
end
|
#template_filename=(template_filename) ⇒ Object
22
23
24
|
# File 'lib/murk/model/stack.rb', line 22
def template_filename=(template_filename)
@template = Template.new(template_filename)
end
|
#wait(state) ⇒ Object
58
59
60
|
# File 'lib/murk/model/stack.rb', line 58
def wait state
cloudformation.wait_forever(:stack_create_complete, stack_name: qualified_name) { yield if block_given? }
end
|