Class: Humidifier::Reservoir::Stack

Inherits:
Object
  • Object
show all
Defined in:
lib/humidifier/reservoir/stack.rb

Overview

Represents a CloudFormation stack. This contains all of the logic for interfacing with humidifier to deploy stacks, validate them, and display them.

Defined Under Namespace

Classes: Export

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, pattern: nil, prefix: nil) ⇒ Stack

Returns a new instance of Stack



22
23
24
25
26
27
# File 'lib/humidifier/reservoir/stack.rb', line 22

def initialize(name, pattern: nil, prefix: nil)
  @name    = name
  @pattern = pattern
  @prefix  = prefix
  @exports = []
end

Instance Attribute Details

#exportsObject (readonly)

Returns the value of attribute exports



20
21
22
# File 'lib/humidifier/reservoir/stack.rb', line 20

def exports
  @exports
end

#nameObject (readonly)

Returns the value of attribute name



20
21
22
# File 'lib/humidifier/reservoir/stack.rb', line 20

def name
  @name
end

#patternObject (readonly)

Returns the value of attribute pattern



20
21
22
# File 'lib/humidifier/reservoir/stack.rb', line 20

def pattern
  @pattern
end

#prefixObject (readonly)

Returns the value of attribute prefix



20
21
22
# File 'lib/humidifier/reservoir/stack.rb', line 20

def prefix
  @prefix
end

Instance Method Details

#create_change_setObject



29
30
31
32
33
34
35
# File 'lib/humidifier/reservoir/stack.rb', line 29

def create_change_set
  return unless ensure_resources
  valid?

  opts = { capabilities: %w[CAPABILITY_IAM CAPABILITY_NAMED_IAM] }
  humidifier_stack.create_change_set(opts)
end

#deploy(wait = false) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/humidifier/reservoir/stack.rb', line 37

def deploy(wait = false)
  return unless ensure_resources
  valid?

  opts = { capabilities: %w[CAPABILITY_IAM CAPABILITY_NAMED_IAM] }
  wait ? humidifier_stack.deploy_and_wait(opts) : humidifier_stack.deploy(opts)
end

#resourcesObject



45
46
47
48
49
# File 'lib/humidifier/reservoir/stack.rb', line 45

def resources
  Reservoir.files_for(name).each_with_object({}) do |filepath, resources|
    resources.merge!(parse(filepath, File.basename(filepath, '.yml')))
  end
end

#stack_nameObject



51
52
53
# File 'lib/humidifier/reservoir/stack.rb', line 51

def stack_name
  @stack_name ||= "#{prefix || Reservoir.stack_prefix}#{name}"
end

#to_cfObject



55
56
57
# File 'lib/humidifier/reservoir/stack.rb', line 55

def to_cf
  humidifier_stack.to_cf
end

#valid?Boolean

Returns:

  • (Boolean)


59
60
61
62
63
64
65
66
# File 'lib/humidifier/reservoir/stack.rb', line 59

def valid?
  humidifier_stack.valid?
rescue Aws::CloudFormation::Errors::AccessDenied
  raise Error, <<-MSG
The authenticated AWS profile does not have the requisite permissions to run
this command. Ensure the profile has cloudformation:ValidateTemplate.
MSG
end