Class: Murk::Model::Stack

Inherits:
Object
  • Object
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: nil, template_filename: name + '.json') ⇒ Stack

Returns a new instance of Stack.



14
15
16
17
18
19
# File 'lib/murk/model/stack.rb', line 14

def initialize(name, env: nil, template_filename: name + '.json')
  @name = name
  @env = env
  @template = Template.new(template_filename)
  @parameters = []
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



12
13
14
# File 'lib/murk/model/stack.rb', line 12

def env
  @env
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/murk/model/stack.rb', line 12

def name
  @name
end

#templateObject (readonly)

Returns the value of attribute template.



12
13
14
# File 'lib/murk/model/stack.rb', line 12

def template
  @template
end

Instance Method Details

#add_parameter(parameter) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/murk/model/stack.rb', line 25

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_updateObject



37
38
39
40
# File 'lib/murk/model/stack.rb', line 37

def create_or_update
  fail StackError, "Stack '#{@name}' is in failed state" if failed?
  exists? ? update : create
end

#deleteObject



42
43
44
45
# File 'lib/murk/model/stack.rb', line 42

def delete
  fail StackError "Stack #{@name} does not exist" unless exists?
  cloudformation.delete_stack(stack_name: qualified_name)
end

#exists?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/murk/model/stack.rb', line 47

def exists?
  existing.any?
end

#failed?Boolean

Returns:

  • (Boolean)


51
52
53
54
55
# File 'lib/murk/model/stack.rb', line 51

def failed?
  existing.any? do |stack|
    stack.stack_status =~ /FAILED/
  end
end

#output(key) ⇒ Object



68
69
70
71
72
73
# File 'lib/murk/model/stack.rb', line 68

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



33
34
35
# File 'lib/murk/model/stack.rb', line 33

def parameter_value(parameter_key)
  @parameters.find { |parameter| parameter.key == parameter_key }.resolve
end

#qualified_nameObject



57
58
59
60
61
62
63
64
65
66
# File 'lib/murk/model/stack.rb', line 57

def qualified_name
  qualified_name = ''
  if Murk.options[:stack_prefix]
    qualified_name += Murk.options[:stack_prefix] + '-'
  end
  if @env
    qualified_name += @env + '-'
  end
  qualified_name + @name
end

#template_filename=(template_filename) ⇒ Object



21
22
23
# File 'lib/murk/model/stack.rb', line 21

def template_filename=(template_filename)
  @template = Template.new(template_filename)
end