Class: Moonshot::ParentStackParameterLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/moonshot/parent_stack_parameter_loader.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ ParentStackParameterLoader

Returns a new instance of ParentStackParameterLoader.



3
4
5
# File 'lib/moonshot/parent_stack_parameter_loader.rb', line 3

def initialize(config)
  @config = config
end

Instance Method Details

#load!Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/moonshot/parent_stack_parameter_loader.rb', line 7

def load!
  @config.parent_stacks.each do |stack_name|
    count = 0

    resp = cf_client.describe_stacks(stack_name: stack_name)
    raise "Parent Stack #{stack_name} not found!" unless resp.stacks.size == 1

    # If there is an input parameters matching a stack output, pass it.
    resp.stacks[0].outputs.each do |output|
      next unless @config.parameters.key?(output.output_key)
      # Our Stack has a Parameter matching this output. Set it's
      # value to the Output's value.
      count += 1
      @config.parameters.fetch(output.output_key).set(output.output_value)
    end

    puts "Imported #{count} parameters from parent stack #{stack_name.blue}!" if count > 0
  end
end

#load_missing_only!Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/moonshot/parent_stack_parameter_loader.rb', line 27

def load_missing_only!
  @config.parent_stacks.each do |stack_name|
    resp = cf_client.describe_stacks(stack_name: stack_name)
    raise "Parent Stack #{stack_name} not found!" unless resp.stacks.size == 1

    # If there is an input parameters matching a stack output, pass it.
    resp.stacks[0].outputs.each do |output|
      next unless @config.parameters.key?(output.output_key)
      # Our Stack has a Parameter matching this output. Set it's
      # value to the Output's value, but only if we don't already
      # have a previous value we're using.
      unless @config.parameters.fetch(output.output_key).use_previous?
        @config.parameters.fetch(output.output_key).set(output.output_value)
      end
    end
  end
end