Method: CloudFormationTool::CloudFormation#load_files

Defined in:
lib/cloud_formation_tool/cloud_formation.rb

#load_files(data, restype = nil) ⇒ Object



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/cloud_formation_tool/cloud_formation.rb', line 186

def load_files(data, restype = nil)
  case data
  when Array
    data.collect { |data| load_files(data, restype) }
  when Hash
    # remember the current resource type
    restype = data['Type'] if restype.nil? and data.key?('Type')
    data.inject({}) do |dict, (key, val)|
      dict[key] = case restype
        when 'AWS::AutoScaling::LaunchConfiguration', 'AWS::EC2::LaunchTemplate'
          if (key == "UserData") and (val["File"]) 
            # Support LaunchConfiguration UserData from file
            CloudInit.new("#{@basedir}/#{val["File"]}").to_base64
          elsif (key == "UserData") and (val["FileTemplate"]) 
            # Support LaunchConfiguration UserData from file with substitutions
            { "Fn::Base64" => { "Fn::Sub" => CloudInit.new("#{@basedir}/#{val["FileTemplate"]}").compile } }
          else
            load_files(val, restype)
          end
        when 'AWS::Lambda::Function'
          if key == 'Code'
            LambdaCode.new(val, self, data['Runtime']).to_cloudformation
          else
            load_files(val, restype)
          end
        when 'AWS::CloudFormation::Stack'
          if key == 'Properties' and val.key?('Template')
            NestedStack.new(val, self).to_cloudformation
          else
            load_files(val, restype)
          end
        else
          load_files(val, restype)
      end
      dict
    end
  else
    data
  end
end