Table of contents
Metadata
You can use the metadata section to provide arbitrary YAML or JSON
Info on Metadata from AWS can be found here
The metadata() function can take a JsonNode or you can make use of the json() function.
metadata(json(mapOf(
"Instances" to mapOf("Description" to "Information about the instances"),
"Databases" to mapOf("Description" to "Information about the databases")
)))
Produces
Metadata:
Instances:
Description: "Information about the instances"
Databases:
Description: "Information about the databases"
Metadata on Resources
To add metadata json to resources you can set the metatdata property on ResourceProperties passed to any resource.
val instanceProperties = ResourceProperties(
metadata = json(mapOf(
. . .
))
)
instance(resourceProperties = instanceProperties) {
imageId("ami-1232131")
}
Some resources have special metadata keys that can be applied. For example the instance resource can be supplied with AWS::Cloudformation::Init to provide initialisation information to the instance.
AWS::CloudFormation::Init
Info on AWS::CloudFormation::Init from AWS can be found here
Inside the map passed to the json function you can invoke the cfnInitMetadata { } function.
val instanceProperties = ResourceProperties(
metadata = json(mapOf(
cfnInitMetadata {
. . .
}
))
)
instance(resourceProperties = instanceProperties) {
imageId("ami-1232131")
}
ConfigSets
cfnInitMetadata {
// Config Set with one config named 1
configSet("test1", +"1")
// Config Set with one config set named test1 and one config named 2
configSet("test2", configSetRef("test1"), +"2")
// A default Config Set referencing Config Set named test2
defaultConfigSet(configSetRef("test2"))
}
Config
cfnInitMetadata {
. . .
// Config named 1
config("1") { . . . }
// Default Config
defaultConfig { . . . }
}
Commands
cfnInitMetadata {
defaultConfig {
command(name = "test", command = +"echo \"${'$'}MAGIC\" > test.txt") {
env("MAGIC" to +"I come from the environment!")
cwd("~")
test("test ! -e ~/test.txt")
ignoreErrors(false)
}
}
}
Files
defaultConfig {
files {
"/tmp/setup.mysql"(
content = +"CREATE DATABASE " + dbName.ref() + ";\n" +
"CREATE USER '" + dbUsername.ref() + "'@'localhost' IDENTIFIED BY '" + dbPassword.ref() + "';\n"
){
mode("000644")
owner("root")
group("root")
}
}
}
Groups
defaultConfig {
groups {
"groupOne" { }
"groupTwo" { gid("45") }
}
}
Packages
defaultConfig {
packages {
PackageManager.rpm {
"epel"("http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm")
}
PackageManager.yum {
"httpd"(emptyList())
"php"(emptyList())
"wordpress"(emptyList())
}
PackageManager.rubygems {
"chef"(listOf("0.10.2"))
}
"other" {
"package"("location")
}
}
}
Services
defaultConfig {
services {
"sysvinit" {
"nginx" {
enabled(true)
ensureRunning(true)
files(listOf(+"/etc/nginx/nginx.conf"))
sources(listOf(+"/var/www/html"))
}
}
}
}
Sources
defaultConfig {
source("/etc/puppet", "https://github.com/user1/cfn-demo/tarball/master")
}
Users
defaultConfig {
users {
"myUser"(
uid = +"50g",
groups = +listOf(+"groupOne", +"groupTwo"),
homeDir = +"/tmp"
)
}
}