Class: Jets::Stack::Output::Lookup

Inherits:
Object
  • Object
show all
Includes:
AwsServices
Defined in:
lib/jets/stack/output/lookup.rb

Instance Method Summary collapse

Methods included from AwsServices

#apigateway, #aws_lambda, #aws_options, #cfn, #dynamodb, #logs, #s3, #s3_resource, #sns, #sqs, #sts

Methods included from AwsServices::StackStatus

#lookup, #stack_exists?, #stack_in_progress?

Methods included from AwsServices::GlobalMemoist

included

Constructor Details

#initialize(stack_subclass) ⇒ Lookup

Returns a new instance of Lookup.



5
6
7
# File 'lib/jets/stack/output/lookup.rb', line 5

def initialize(stack_subclass)
  @stack_subclass = stack_subclass
end

Instance Method Details

#output(logical_id) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/jets/stack/output/lookup.rb', line 9

def output(logical_id)
  child_stack_id = @stack_subclass.to_s.camelize

  stack_arn = shared_stack_arn(child_stack_id)
  resp = cfn.describe_stacks(stack_name: stack_arn)
  child = resp.stacks.first
  return unless child

  output_value(child, logical_id)
end

#output_value(stack, key) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/jets/stack/output/lookup.rb', line 28

def output_value(stack, key)
  key = key.to_s.camelize
  output = stack.outputs.find do |o|
    o.output_key == key
  end
  output&.output_value
end

#shared_stack_arn(logical_id) ⇒ Object

Shared child stack arn



21
22
23
24
25
26
# File 'lib/jets/stack/output/lookup.rb', line 21

def shared_stack_arn(logical_id)
  parent_stack = Jets.config.project_namespace
  resp = cfn.describe_stacks(stack_name: parent_stack)
  parent = resp.stacks.first
  output_value(parent, logical_id)
end