class CfnFlow::StackParams

Extend hash with some special behavior to generate the style of hash aws-sdk expects

Public Class Methods

expanded(hash) click to toggle source
# File lib/cfn_flow/stack_params.rb, line 6
def self.expanded(hash)
  self[hash].
    with_symbolized_keys.
    with_expanded_parameters.
    with_expanded_tags.
    with_expanded_template_body
end

Public Instance Methods

add_tag(hash) click to toggle source
# File lib/cfn_flow/stack_params.rb, line 40
def add_tag(hash)
  new_tags = hash.map do |k,v|
    {key: k, value: v }
  end
  tags = (self[:tags] || []) + new_tags
  self.merge(tags: tags)
end
with_expanded_parameters() click to toggle source
# File lib/cfn_flow/stack_params.rb, line 20
def with_expanded_parameters
  return self unless self[:parameters].is_a? Hash

  expanded_params = self[:parameters].map do |key,value|
    { parameter_key: key, parameter_value: fetch_value(key, value) }
  end

  self.merge(parameters: expanded_params)
end
with_expanded_tags() click to toggle source
# File lib/cfn_flow/stack_params.rb, line 30
def with_expanded_tags
  return self unless self[:tags].is_a? Hash

  tags = self[:tags].map do |key, value|
    {key: key, value: value}
  end

  self.merge(tags: tags)
end
with_expanded_template_body() click to toggle source
# File lib/cfn_flow/stack_params.rb, line 48
def with_expanded_template_body
  return self unless self[:template_body].is_a? String
  body = CfnFlow::Template.new(self[:template_body]).to_json
  self.merge(template_body: body)
rescue CfnFlow::Template::Error
  # Do nothing
  self
end
with_symbolized_keys() click to toggle source
# File lib/cfn_flow/stack_params.rb, line 14
def with_symbolized_keys
  self.reduce(StackParams.new) do |accum, (key, value)|
    accum.merge(key.to_sym => value)
  end
end

Private Instance Methods

fetch_value(key, value) click to toggle source
# File lib/cfn_flow/stack_params.rb, line 57
def fetch_value(key, value)
  # Dereference stack output params
  if value.is_a?(Hash) && value.key?('stack')
    stack_name = value['stack']
    stack_output_name = value['output'] || key

    value = CachedStack.get_output(stack: stack_name, output: stack_output_name)
  else
    value
  end
end