Class: StackMaster::ParameterResolvers::StackOutput

Inherits:
Resolver
  • Object
show all
Defined in:
lib/stack_master/parameter_resolvers/stack_output.rb

Constant Summary collapse

StackNotFound =
Class.new(StandardError)
StackOutputNotFound =
Class.new(StandardError)

Instance Method Summary collapse

Methods inherited from Resolver

array_resolver

Constructor Details

#initialize(config, stack_definition) ⇒ StackOutput

Returns a new instance of StackOutput.



9
10
11
12
13
14
15
# File 'lib/stack_master/parameter_resolvers/stack_output.rb', line 9

def initialize(config, stack_definition)
  @config = config
  @stack_definition = stack_definition
  @stacks = {}
  @cf_drivers = {}
  @output_regex = %r{(?:(?<region>[^:]+):)?(?<stack_name>[^:/]+)/(?<output_name>.+)}
end

Instance Method Details

#resolve(value) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/stack_master/parameter_resolvers/stack_output.rb', line 17

def resolve(value)
  region, stack_name, output_name = parse!(value)
  stack = find_stack(stack_name, region)
  if stack
    output = stack.outputs.find { |stack_output| stack_output.output_key == output_name.camelize }
    if output
      output.output_value
    else
      raise StackOutputNotFound, "Stack exists (#{stack_name}), but output does not: #{output_name}"
    end
  else
    raise StackNotFound, "Stack in StackOutput not found: #{value}"
  end
end