Method: CloudFormationTool::CloudFormation#resolveVal

Defined in:
lib/cloud_formation_tool/cloud_formation.rb

#resolveVal(value) ⇒ Object



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/cloud_formation_tool/cloud_formation.rb', line 163

def resolveVal(value)
  case value
  when Hash
    if value.key? 'Ref'
      if @params.nil?
        # no parameters, we are probably in a sub template, just return the ref and hope
        # a parent template has what it takes to resolve the ref
        value
      else # parameters are set for this template - we can try to resolve
        res = @params[value['Ref']] || ((@data['Parameters']||{})[value['Ref']] || {})['Default']
        if res.nil?
          raise CloudFormationTool::Errors::AppError, "Reference #{value['Ref']} can't be resolved"
        end
        res
      end
    else
      raise CloudFormationTool::Errors::AppError, "Value #{value} is not a valid value or reference"
    end
  else
    value
  end
end