Class: StackMaster::CloudFormationTemplateEruby

Inherits:
Erubis::Eruby
  • Object
show all
Defined in:
lib/stack_master/cloudformation_template_eruby.rb

Overview

This class is a modified version of ‘Erubis::Eruby`. It provides extra helper methods to ease the dynamic creation of CloudFormation templates with ERB. These helper methods are available within `<%= %>` expressions.

Instance Method Summary collapse

Instance Method Details

#include_file(filepath) ⇒ Object

Add the contents of another file into the CloudFormation template as a string. ERB ‘<%= %>` expressions within the referenced file are not evaluated.



28
29
30
# File 'lib/stack_master/cloudformation_template_eruby.rb', line 28

def include_file(filepath)
  JSON.pretty_generate(File.read(filepath))
end

#user_data_file(filepath) ⇒ Object

Adds the contents of an EC2 userdata script to the CloudFormation template. Allows using the ERB ‘<%= %>` expressions within the user data script to interpolate CloudFormation values.



14
15
16
# File 'lib/stack_master/cloudformation_template_eruby.rb', line 14

def user_data_file(filepath)
  JSON.pretty_generate({ 'Fn::Base64' => { 'Fn::Join' => ['', user_data_file_as_lines(filepath)] } })
end

#user_data_file_as_lines(filepath) ⇒ Object

Evaluate the ERB template at the specified filepath and return the result as an array of lines. Allows using ERB ‘<%= %>` expressions to interpolate CloudFormation objects into the result.



21
22
23
# File 'lib/stack_master/cloudformation_template_eruby.rb', line 21

def user_data_file_as_lines(filepath)
  StackMaster::CloudFormationInterpolatingEruby.evaluate_file(filepath, self)
end