Skip to content

Commit

Permalink
Merge pull request #53 from adamfokken/cgwsupport
Browse files Browse the repository at this point in the history
Add AWS::EC2::CustomerGateway support
  • Loading branch information
T.J. Corrigan committed Jan 19, 2016
2 parents 7ca1c22 + ec247f6 commit a2dc2b3
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ describe("Template Lookup") {
- AWS::AutoScaling::ScalingPolicy
- AWS::CloudWatch::Alarm
- AWS::DynamoDB::Table
- AWS::EC2::CustomerGateway
- AWS::EC2::EIP
- AWS::EC2::Instance
- AWS::EC2::InternetGateway
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ object `AWS::EC2::KeyPair::KeyName` extends DefaultJsonProtocol {
implicit val format: JsonFormat[`AWS::EC2::KeyPair::KeyName`] = jsonFormat2(`AWS::EC2::KeyPair::KeyName`.apply)
}

case class `AWS::EC2::CustomerGateway`(
name: String,
BgpAsn: Int,
IpAddress: IPAddress,
Tags: Seq[AmazonTag],
Type: String,
override val Condition: Option[ConditionRef] = None) extends Resource[`AWS::EC2::CustomerGateway`]{

def when(newCondition: Option[ConditionRef] = Condition) = copy(Condition = newCondition)
}
object `AWS::EC2::CustomerGateway` extends DefaultJsonProtocol {
implicit val format: JsonFormat[`AWS::EC2::CustomerGateway`] = jsonFormat6(`AWS::EC2::CustomerGateway`.apply)
}

@implicitNotFound("A Route can only have exactly ONE of GatewayId, InstanceId, NetworkInterfaceId or VpcPeeringConnectionId set")
class ValidRouteCombo[G, I, P] private ()
object ValidRouteCombo{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import scala.reflect.NameTransformer

// serializes to Type and Properties
abstract class Resource[R <: Resource[R] : ClassTag : JsonFormat]{ self: Resource[R] =>
val Type = NameTransformer.decode(implicitly[ClassTag[R]].runtimeClass.getSimpleName)
val ResourceType = NameTransformer.decode(implicitly[ClassTag[R]].runtimeClass.getSimpleName)
val name: String

val Condition: Option[ConditionRef] = None
Expand All @@ -37,7 +37,7 @@ object Resource extends DefaultJsonProtocol {
val raw = bar._format.asInstanceOf[JsonFormat[obj.RR]].write(bar).asJsObject

val outputFields = Map(
"Type" -> JsString(obj.Type),
"Type" -> JsString(obj.ResourceType),
"Metadata" -> raw.fields.getOrElse("Metadata", JsNull),
"Properties" -> JsObject(raw.fields - "name" - "Metadata" - "UpdatePolicy" - "Condition" - "DependsOn" - "DeletionPolicy"),
"UpdatePolicy" -> raw.fields.getOrElse("UpdatePolicy", JsNull),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.monsanto.arch.cloudformation.model.resource

import com.monsanto.arch.cloudformation.model._
import org.scalatest.{FunSpec, Matchers}
import spray.json._

class CGW_UT extends FunSpec with Matchers {
describe("AWS::EC2::CustomerGateway") {
val bpgAsn = 1234
val ipAddr = IPAddress(8, 8, 8, 8)
val cgwType = "ipsec.1"
val cgw = `AWS::EC2::CustomerGateway`(
name = "cgw",
BgpAsn = 1234,
IpAddress = ipAddr,
Tags = Seq(),
Type = "ipsec.1"
)
it("should create a valid new Customer Gateway") {
val expected = JsObject(
"cgw" -> JsObject(
"Type" -> JsString("AWS::EC2::CustomerGateway"),
"Properties" -> JsObject(
"BgpAsn" -> JsNumber(bpgAsn),
"IpAddress" -> ipAddr.toJsString,
"Tags" -> JsArray(),
"Type" -> JsString(cgwType)
)
)
)
Seq[Resource[_]](cgw).toJson should be(expected)
}
}
}

0 comments on commit a2dc2b3

Please sign in to comment.