Merge multiple CloudFormation template files into a single template. Each file may be in either JSON or YAML format.
Get started with template = MkStack::Template.new, or use the command line tool mkstack.
By default all files are run through an ERB (Embedded RuBy) processor.
<% desc = "awesome" %>
AWSTemplateFormatVersion: "2010-09-09"
Description: My <%= desc %> CloudFormation template
It is safe to leave this enabled. If a file doesn't have any ERB tags it is passed through untouched.
MkStack searches each file for a section named Include, which should be a list of filenames. These function the same as adding the listed files on the command line.
"Include" : [
"foo.yaml",
"bar.json"
]
Include:
- foo.yaml
- bar.json
MkStack uses a single binding for all files. This allows ERB tags defined in one file to be referenced in subsequent files.
Include:
- bar.json
<% tags_json = %q{
"Tags": [
{ "Key" : "application", "Value" : "mkstack" }
]
}
%>
{
"Resources" : {
"sg": {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" : {
"GroupDescription" : {
"Fn::Sub" : "Security Group for ${application}"
}
<%= tags_json %>
}
}
}
}
Note that foo.yaml is processed before bar.json.
Usage: mkstack [ options ] file1 [ file2... ]
-h, --help Display this message
--version Show version
-d, --debug Show debug messages
-v, --verbose Be verbose
-q, --quiet Only show errors
-s, --silent Don't show any log messages
-o, --output=FILE Print final template to FILE
Use '-' for stdout
-f, --format=FORMAT Print as FORMAT
Supported formats: json (default), yaml
--erb, --[no-]erb Perform ERB processing (default is true)
--validate Call ValidateTemplate after merging
--- Marks end of mkstack options
Remaining arguments are available to ERB as Array argv
Any command line arguments following "---" are added to an Array called argv, which can be referenced in your ERB code.
<% puts "#{argv.class} with #{argv.length} items: #{argv}" %>
$ mkstack foo.yaml --- a 2 test
Array with 3 items: ["a", "2", "test"]