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
# File 'lib/humidifier/reservoir/stack.rb', line 29

def create_change_set
  return if !ensure_resources('change') || !valid?

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

#deploy(wait = false, parameter_values = {}) ⇒ Object



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

def deploy(wait = false, parameter_values = {})
  return if !ensure_resources('deploy') || !valid?

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

#parametersObject



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/humidifier/reservoir/stack.rb', line 46

def parameters
  @parameters ||=
    begin
      parameter_filepath =
        Reservoir.files_for(name).detect do |filepath|
          File.basename(filepath, '.yml') == 'parameters'
        end

      parameter_filepath ? ParameterList.from(parameter_filepath) : {}
    end
end

#resourcesObject



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

def resources
  Reservoir.files_for(name).each_with_object({}) do |filepath, resources|
    basename = File.basename(filepath, '.yml')

    # Explicitly skip past parameters so we can pull them out later
    next if basename == 'parameters'

    resources.merge!(parse(filepath, basename))
  end
end

#stack_nameObject



69
70
71
# File 'lib/humidifier/reservoir/stack.rb', line 69

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

#to_cfObject



73
74
75
# File 'lib/humidifier/reservoir/stack.rb', line 73

def to_cf
  humidifier_stack.to_cf
end

#uploadObject



77
78
79
80
# File 'lib/humidifier/reservoir/stack.rb', line 77

def upload
  return if !ensure_resources('upload') || !valid?
  humidifier_stack.upload
end

#valid?Boolean

Returns:

  • (Boolean)


82
83
84
85
86
87
88
89
90
# File 'lib/humidifier/reservoir/stack.rb', line 82

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