Packages

  • package root
    Definition Classes
    root
  • package com
    Definition Classes
    root
  • package monsanto
    Definition Classes
    com
  • package arch
    Definition Classes
    monsanto
  • package cloudformation
    Definition Classes
    arch
  • package model

    A DSL to create consistent, type-safe AWS CloudFormation templates.

    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.

    Definition Classes
    cloudformation
  • package resource
    Definition Classes
    model
  • package simple
    Definition Classes
    model
  • Autoscaling
  • AvailabilityZone
  • Builders
  • Conditions
  • EC2
  • ElasticLoadBalancing
  • Gateway
  • Instance
  • Outputs
  • Route
  • Route53
  • SecurityGroup
  • SecurityGroupRoutable
  • SecurityGroupRoutableMaker
  • Subnet
  • VPC
  • Yaml

package simple

Ordering
  1. Alphabetic
Visibility
  1. Public
  2. All

Type Members

  1. trait Autoscaling extends AnyRef
  2. trait AvailabilityZone extends AnyRef
  3. trait Conditions extends AnyRef
  4. trait EC2 extends AnyRef
  5. trait ElasticLoadBalancing extends AnyRef
  6. trait Gateway extends AnyRef
  7. trait Instance extends AnyRef
  8. trait Outputs extends AnyRef
  9. trait Route extends AnyRef
  10. trait Route53 extends AnyRef
  11. trait SecurityGroup extends AnyRef
  12. case class SecurityGroupRoutable[R <: Resource[R]](resource: R, sg: AWS::EC2::SecurityGroup, extras: Option[Seq[Resource[_]]] = None) extends Product with Serializable
  13. trait SecurityGroupRoutableMaker[R <: Resource[R]] extends AnyRef
  14. trait Subnet extends AvailabilityZone with Outputs
  15. trait VPC extends Outputs

Value Members

  1. object Builders extends Route with Instance with Subnet with Route53 with Autoscaling with SecurityGroup with VPC with AvailabilityZone with EC2 with Outputs with Gateway with Conditions with ElasticLoadBalancing
  2. object SecurityGroupRoutable extends Serializable
  3. object SecurityGroupRoutableMaker
  4. object Yaml

Ungrouped