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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, pattern = nil) ⇒ Stack

Returns a new instance of Stack



9
10
11
12
# File 'lib/humidifier/reservoir/stack.rb', line 9

def initialize(name, pattern = nil)
  @name    = name
  @pattern = pattern
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name



7
8
9
# File 'lib/humidifier/reservoir/stack.rb', line 7

def name
  @name
end

#patternObject (readonly)

Returns the value of attribute pattern



7
8
9
# File 'lib/humidifier/reservoir/stack.rb', line 7

def pattern
  @pattern
end

Instance Method Details

#deploy(wait = false) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/humidifier/reservoir/stack.rb', line 14

def deploy(wait = false)
  if humidifier_stack.resources.empty?
    puts "Refusing to deploy stack #{humidifier_stack.name} with no resources"
    return
  end
  valid?

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

#resourcesObject



25
26
27
28
29
# File 'lib/humidifier/reservoir/stack.rb', line 25

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

#stack_nameObject



31
32
33
# File 'lib/humidifier/reservoir/stack.rb', line 31

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

#to_cfObject



35
36
37
# File 'lib/humidifier/reservoir/stack.rb', line 35

def to_cf
  humidifier_stack.to_cf
end

#valid?Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
45
46
# File 'lib/humidifier/reservoir/stack.rb', line 39

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