package model
A DSL to create consistent, type-safe AWS CloudFormation templates.
The low-level DSL closely adheres to the objects and parameters in the CloudFormation template JSON specification. If you intend to use this DSL to create CloudFormation templates, it would behoove you to familiarize yourself with the CloudFormation documentation.
In addition to the low-level, DSL, there are several higher-order builders and convenience methods. See com.monsanto.arch.cloudformation.model.simple.Builders for more information on these helper methods.
For a discussion of the features and approach of this library, read our blog post.
Sample usage:
import com.monsanto.arch.cloudformation.model._ import com.monsanto.arch.cloudformation.model.resource._ import com.monsanto.arch.cloudformation.model.simple.Builders._ object SimpleVPC extends VPCWriter { val ownerParameter = StringParameter( name = "Owner", Description = Some("Individual responsible for this template"), MinLength = Some(StringBackedInt(1)), MaxLength = Some(StringBackedInt(64)), AllowedPattern = Some("[-_ a-zA-Z0-9]*"), ConstraintDescription = Some("Can contain only alphanumeric characters, spaces, dashes and underscores.") ) val keyNameParameter = `AWS::EC2::KeyPair::KeyName_Parameter`( name = "KeyName", Description = Some("Name of an existing EC2 KeyPair to enable SSH access to the instances"), ConstraintDescription = Some("Value must be a valid AWS key pair name in your account.") ) val allowSSHFromParameter = CidrBlockParameter( name = "AllowSSHFrom", Description = Some("The net block (CIDR) that SSH is available to.") ) val simpleParameters = Seq( ownerParameter, keyNameParameter, allowSSHFromParameter ) val simpleConditions = Seq( Condition( name = "ShouldDisablePassword", function = `Fn::Equals`( a = ParameterRef(ownerParameter), b = StringToken("rms") ) ) ) val amazonLinuxAMIMapping = Mapping[AMIId]( "AmazonLinuxAMI", Map( "us-east-1" -> Map("AMI" -> AMIId("ami-1ecae776")), "us-west-1" -> Map("AMI" -> AMIId("ami-d114f295")), "us-west-2" -> Map("AMI" -> AMIId("ami-e7527ed7")), "eu-west-1" -> Map("AMI" -> AMIId("ami-a10897d6")), "ap-southeast-1" -> Map("AMI" -> AMIId("ami-68d8e93a")), "ap-southeast-2" -> Map("AMI" -> AMIId("ami-fd9cecc7")), "ap-northeast-1" -> Map("AMI" -> AMIId("ami-cbf90ecb")) ) ) val simpleMappings = Seq(amazonLinuxAMIMapping) val simpleResourceAndOutputs = withVpc(CidrBlock(10, 0, 0, 0, 16)) { implicit vpc => val (internetGatewayResource, gatewayToInternetResource) = withInternetGateway val publicRouteTable = withRouteTable("Public", 1) val publicRouteTableRoute = publicRouteTable.withRoute( visibility = "Public", routeTableOrdinal = 1, routeOrdinal = 1, connectionBobber = InternetGatewayRoute(ResourceRef(internetGatewayResource)) ) val gatewayStuff = Template.fromResource(internetGatewayResource) ++ gatewayToInternetResource ++ publicRouteTable ++ publicRouteTableRoute val withinAZ = withAZ("us-east-1a") { implicit az => withSubnet("PubSubnet1", CidrBlock(10, 0, 0, 1, 24)) { implicit pubSubnet => val bastionName = "bastion" val bastion = ec2( name = bastionName, InstanceType = "t2.micro", KeyName = ParameterRef(keyNameParameter), ImageId = `Fn::FindInMap`[AMIId](MappingRef(amazonLinuxAMIMapping), `AWS::Region`, "AMI"), SecurityGroupIds = Seq(), Tags = AmazonTag.fromName(bastionName), UserData = Some(`Fn::Base64`( `Fn::Join`("", Seq[Token[String]]( "#!/bin/bash -v\n", "yum update -y --security\n", "# EOF\n" ) ) )) ) val sshToBastion = ParameterRef(allowSSHFromParameter) ->- 22 ->- bastion Template.fromSecurityGroupRoutable(bastion) ++ bastion.map(_.withEIP("BastionEIP").andOutput("BastionEIP", "Bastion Host EIP")) ++ Template.collapse(sshToBastion) } } gatewayStuff ++ withinAZ } val simpleTemplate = simpleResourceAndOutputs ++ Template( AWSTemplateFormatVersion = Some("2010-09-09"), Description = Some("Simple template"), Parameters = Some(simpleParameters), Conditions = Some(simpleConditions), Mappings = Some(simpleMappings), Resources = Seq.empty, Outputs = None ) writeStaxModule("vpc-simple.json", simpleTemplate) } SimpleVPC
The above code utilizes the DSL to create a simple AWS VPC utilizing a single Availability Zone having a single public subnet and a single "bastion" instance. The template output is the IP address of the EIP it creates. It also shows examples of creating and using Parameters and Mappings. A Condition is created but not used.
- Alphabetic
- By Inheritance
- model
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
- case class AMIIdParameter(name: String, Description: Option[String], Default: Option[Token[MappingRef[AMIId]]], AllowedValues: Option[Seq[String]], ConstraintDescription: Option[String], ConfigDefault: Option[String] = None) extends Parameter with Product with Serializable
- case class AWS::EC2::KeyPair::KeyName_Parameter(name: String, Description: Option[String], ConstraintDescription: Option[String] = None, Default: Option[String] = None, ConfigDefault: Option[String] = None) extends Parameter with Product with Serializable
- case class AWS::EC2::SecurityGroup_Parameter(name: String, Description: Option[String], Default: Option[Token[ResourceRef[AWS::EC2::SecurityGroup]]] = None, ConfigDefault: Option[String] = None) extends Parameter with Product with Serializable
- case class AWS::EC2::Subnet_Parameter_List(name: String, Description: Option[String], ConfigDefault: Option[String] = None) extends Parameter with Product with Serializable
- case class AWS::EC2::VPC_Parameter(name: String, Description: Option[String], Default: Option[VpcId] = None, ConfigDefault: Option[String] = None) extends Parameter with Product with Serializable
- case class AWS::RDS::DBInstance::Engine_Parameter(name: String, Description: Option[String], Default: Option[Token[AWS::RDS::DBInstance::Engine]] = None, ConfigDefault: Option[String] = None) extends Parameter with Product with Serializable
- case class AWS::RDS::DBSubnetGroup_Parameter(name: String, Description: Option[String], Default: Option[String] = None, ConfigDefault: Option[String] = None) extends Parameter with Product with Serializable
-
sealed abstract
class
AmazonFunctionCall[LogicalReturnType] extends AnyRef
Created by Ryan Richt on 2/15/15
- case class AnyToken[R](value: R)(implicit evidence$11: JsonFormat[R]) extends Token[R] with Product with Serializable
-
implicit final
class
AwsStringInterpolator extends AnyVal
Provides a string interpolator to assist in the concatenation of
Provides a string interpolator to assist in the concatenation of
The following:
import com.monsanto.arch.cloudformation.model._ val param = ParameterRef(StringParameter("that")) val fun = aws"test$param"
Will generate the following FunctionCall definition:
FunctionCallToken(`Fn::Join`("", Seq(StringToken("test"), param)))
- case class BooleanParameter(name: String, Description: Option[String] = None, Default: Option[Boolean] = None, ConfigDefault: Option[String] = None) extends Parameter with Product with Serializable
- case class BooleanToken(value: Boolean) extends Token[Boolean] with Product with Serializable
- case class CidrBlockListParameter(name: String, Description: Option[String], Default: Option[Seq[CidrBlock]] = None, ConfigDefault: Option[String] = None) extends Parameter with Product with Serializable
- case class CidrBlockParameter(name: String, Description: Option[String], Default: Option[CidrBlock] = None, ConfigDefault: Option[String] = None) extends Parameter with Product with Serializable
-
case class
Condition(name: String, function: Token[String]) extends Product with Serializable
Created by bkrodg on 2/16/15.
- case class ConditionFnRef(c: Condition) extends NestableAmazonFunctionCall[String] with Product with Serializable
- sealed trait ConditionFunctionNestable[LogicalReturnType] extends AnyRef
- case class ConditionRef(c: Condition) extends Product with Serializable
- class EnumFormat[T] extends JsonFormat[T]
- case class Fn::And(fn: Seq[ConditionFunctionNestable[String]]) extends NestableAmazonFunctionCall[String] with Product with Serializable
- case class Fn::Base64(toEncode: Token[String]) extends AmazonFunctionCall[String] with Product with Serializable
- case class Fn::Equals(a: Token[String], b: Token[String]) extends NestableAmazonFunctionCall[String] with Product with Serializable
- case class Fn::FindInMap[R](mapName: Token[MappingRef[R]], outerKey: Token[String], innerKey: Token[String]) extends AmazonFunctionCall[String] with Product with Serializable
- case class Fn::GetAZs(region: Token[String]) extends AmazonFunctionCall[Seq[String]] with Product with Serializable
- case class Fn::GetArtifactAtt(artifactName: String, attributeName: String) extends AmazonFunctionCall[String] with Product with Serializable
- case class Fn::GetAtt(args: Seq[String]) extends AmazonFunctionCall[String] with Product with Serializable
- case class Fn::GetParam(artifactName: String, jsonFileName: String, keyName: String) extends AmazonFunctionCall[String] with Product with Serializable
- case class Fn::If[R](conditionName: Token[ConditionRef], valIfTrue: Token[R], valIfFalse: Token[R])(implicit evidence$2: JsonFormat[R]) extends AmazonFunctionCall[R] with Product with Serializable
- case class Fn::ImportValue(importValue: Token[String]) extends AmazonFunctionCall[String] with Product with Serializable
- case class Fn::Join(joinChar: String, toJoin: Seq[Token[String]]) extends AmazonFunctionCall[String] with Product with Serializable
- case class Fn::Not(fn: ConditionFunctionNestable[String]) extends NestableAmazonFunctionCall[String] with Product with Serializable
- case class Fn::Or(fn: Seq[ConditionFunctionNestable[String]]) extends NestableAmazonFunctionCall[String] with Product with Serializable
- case class Fn::Select[R](index: Token[StringBackedInt], listOfObjects: Token[Seq[R]])(implicit evidence$1: JsonFormat[R]) extends AmazonFunctionCall[R] with Product with Serializable
- case class Fn::Split(delimiterChar: String, toSplit: Token[String]) extends AmazonFunctionCall[Seq[String]] with Product with Serializable
- case class Fn::Sub(template: Token[String], subs: Option[Map[Token[String], Token[String]]] = None) extends AmazonFunctionCall[String] with Product with Serializable
- case class FunctionCallSeqToken[R](call: AmazonFunctionCall[Seq[R]]) extends Token[Seq[R]] with Product with Serializable
- case class FunctionCallToken[R](call: AmazonFunctionCall[R]) extends Token[R] with Product with Serializable
- trait HasTemplate extends AnyRef
- case class If[R](conditionName: Token[String], valIfTrue: Token[R], valIfFalse: Token[String] = `AWS::NoValue`)(implicit evidence$3: JsonFormat[R]) extends AmazonFunctionCall[R] with Product with Serializable
- case class InputParameter(ParameterKey: String, ParameterValue: JsValue = "<changeMe>".toJson) extends Product with Serializable
- case class IntToken(value: Int) extends Token[Int] with Product with Serializable
-
case class
JsonWritable[T](thing: T)(implicit evidence$1: JsonWriter[T]) extends Product with Serializable
Wrapper for anything that can be written to Json.
Wrapper for anything that can be written to Json. Useful to allow specifying a Map of String -> JsonWritable that can take any value that can be written out as Json.
-
case class
Mapping[A](name: String, map: Map[String, Map[String, A]])(implicit formatter: JsonFormat[A]) extends Product with Serializable
Created by Ryan Richt on 2/15/15
- case class MappingRef[R](m: Mapping[R]) extends Product with Serializable
- sealed abstract class NestableAmazonFunctionCall[LogicalReturnType] extends AmazonFunctionCall[LogicalReturnType] with ConditionFunctionNestable[LogicalReturnType]
- case class NumberParameter(name: String, Description: Option[String] = None, MinValue: Option[StringBackedInt] = None, MaxValue: Option[StringBackedInt] = None, ConstraintDescription: Option[String] = None, Default: Option[StringBackedInt] = None, AllowedValues: Option[Seq[StringBackedInt]] = None, ConfigDefault: Option[String] = None) extends Parameter with Product with Serializable
-
case class
Output[R](name: String, Description: Option[String] = None, Value: Token[R], Export: Option[Token[String]] = None)(implicit format: JsonFormat[Token[R]]) extends Product with Serializable
Created by Ryan Richt on 2/15/15
-
sealed abstract
class
Parameter extends AnyRef
Created by Ryan Richt on 2/15/15
- case class ParameterRef[R](p: Parameter { type Rep = R }) extends AmazonFunctionCall[R] with Product with Serializable
- sealed abstract class PseudoParameterRef extends Token[String]
- case class ResourceRef[R <: Resource[R]](r: R) extends AmazonFunctionCall[R] with Token[String] with Product with Serializable
- case class StringBackedInt(value: Int) extends Product with Serializable
- case class StringListParameter(name: String, Description: Option[String] = None, Default: Option[Seq[String]] = None, NoEcho: Option[Boolean] = None, ConfigDefault: Option[String] = None) extends Parameter with Product with Serializable
- case class StringParameter(name: String, Description: Option[String] = None, MinLength: Option[StringBackedInt] = None, MaxLength: Option[StringBackedInt] = None, AllowedPattern: Option[String] = None, ConstraintDescription: Option[String] = None, Default: Option[String] = None, AllowedValues: Option[Seq[String]] = None, NoEcho: Option[Boolean] = None, ConfigDefault: Option[String] = None) extends Parameter with Product with Serializable
- case class StringToken(value: String) extends Token[String] with Product with Serializable
-
case class
Template(Description: Option[String] = None, Parameters: Option[Seq[Parameter]] = None, Conditions: Option[Seq[Condition]] = None, Mappings: Option[Seq[Mapping[_]]] = None, Resources: Seq[Resource[_]], Routables: Option[Seq[SecurityGroupRoutable[_ <: Resource[_]]]] = None, Outputs: Option[Seq[Output[_]]] = None, AWSTemplateFormatVersion: Option[String] = None) extends Product with Serializable
Template is the container for all the elements of your AWS CloudFormation template.
Template is the container for all the elements of your AWS CloudFormation template.
// create the template val simpleTemplate = Template( Description = Some("Simple S3 Bucket Template"), Resources = Seq( `AWS::S3::Bucket`( name = "S3Bucket", BucketName = Some("UniqueBucketForSimpleTemplate") ) ) )
- Description
See description
- Parameters
See parameters
- Conditions
See conditionals
- Mappings
See mappings
- Resources
See resources
- Outputs
See outputs
- AWSTemplateFormatVersion
See version
-
trait
TemplateBase extends HasTemplate
Finds all val/lazy val/def in the class (using reflection) that produce elements of a template and builds a template from them.
Finds all val/lazy val/def in the class (using reflection) that produce elements of a template and builds a template from them. This search for:
- Parameter
- Condition
- Mapping
- Resource
- SecurityGroupRoutable
- Output
- Template
- HasTemplate
- sealed trait Token[R] extends AnyRef
- case class UNSAFEFunctionCallToken[R](call: AmazonFunctionCall[String]) extends Token[R] with Product with Serializable
-
trait
VPCWriter extends AnyRef
Created by Ryan Richt on 6/19/15
-
case class
UNSAFEToken[R](value: String) extends Token[R] with Product with Serializable
- Annotations
- @deprecated
- Deprecated
(Since version Feb 20 2015) use ParameterRef or ResourceRef instead
Value Members
- implicit def eitherAfuncA2OptionEitherAfuncA[A](v: Either[A, AmazonFunctionCall[A]]): Option[Either[A, Token[A]]]
- implicit val instantFormat: JsonFormat[Instant]
- implicit def lift2Option[A](a: A): Option[A]
- implicit def parameter2TokenString(parameter: StringParameter): Token[String]
-
implicit
lazy val
stringTokenFormat: JsonFormat[Token[String]]
This is to assist in creating Output[Token[String]] objects as it allows the formatter to be in scope.
- object AMIIdParameter extends DefaultJsonProtocol with Serializable
- object AWS::AccountId extends PseudoParameterRef with Product with Serializable
- object AWS::EC2::KeyPair::KeyName_Parameter extends DefaultJsonProtocol with Serializable
- object AWS::EC2::SecurityGroup_Parameter extends DefaultJsonProtocol with Serializable
- object AWS::EC2::Subnet_Parameter_List extends DefaultJsonProtocol with Serializable
- object AWS::EC2::VPC_Parameter extends DefaultJsonProtocol with Serializable
- object AWS::NoValue extends PseudoParameterRef with Product with Serializable
- object AWS::NotificationARNs extends PseudoParameterRef with Product with Serializable
- object AWS::RDS::DBInstance::Engine_Parameter extends DefaultJsonProtocol with Serializable
- object AWS::RDS::DBSubnetGroup_Parameter extends DefaultJsonProtocol with Serializable
- object AWS::Region extends PseudoParameterRef with Product with Serializable
- object AWS::StackId extends PseudoParameterRef with Product with Serializable
- object AWS::StackName extends PseudoParameterRef with Product with Serializable
- object AmazonFunctionCall extends DefaultJsonProtocol
-
object
AwsStringInterpolation
Created by Tyler Southwick on 11/20/15.
- object BooleanParameter extends DefaultJsonProtocol with Serializable
- object CidrBlockListParameter extends DefaultJsonProtocol with Serializable
- object CidrBlockParameter extends DefaultJsonProtocol with Serializable
- object Condition extends DefaultJsonProtocol with Serializable
- object ConditionRef extends DefaultJsonProtocol with Serializable
- object Fn::Base64 extends DefaultJsonProtocol with Serializable
- object Fn::ImportValue extends Serializable
- object Fn::Sub extends Serializable
- object HasTemplate
- object InputParameter extends DefaultJsonProtocol with Serializable
- object JsonWritable extends Serializable
- object Mapping extends DefaultJsonProtocol with Serializable
- object MappingRef extends DefaultJsonProtocol with Serializable
- object NumberParameter extends DefaultJsonProtocol with Serializable
- object Output extends DefaultJsonProtocol with Serializable
- object Parameter extends DefaultJsonProtocol
- object ParameterRef extends DefaultJsonProtocol with Serializable
- object PseudoParameterRef extends DefaultJsonProtocol
- object ResourceRef extends DefaultJsonProtocol with Serializable
- object StringBackedInt extends DefaultJsonProtocol with Serializable
- object StringListParameter extends DefaultJsonProtocol with Serializable
- object StringParameter extends DefaultJsonProtocol with Serializable
- object Template extends DefaultJsonProtocol with Serializable
- object TemplateBase
- object Token extends DefaultJsonProtocol