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.



5
6
7
# File 'lib/moonshot/parent_stack_parameter_loader.rb', line 5

def initialize(config)
  @config = config
end

Instance Method Details

#load!Object



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

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

    resp = cf_client.describe_stacks(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.positive?
  end
end

#load_missing_only!Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/moonshot/parent_stack_parameter_loader.rb', line 30

def load_missing_only!
  @config.parent_stacks.each do |stack_name|
    resp = cf_client.describe_stacks(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