Skip to content

Commit

Permalink
Merge pull request #57 from mackinac/fn-getazs
Browse files Browse the repository at this point in the history
Add support for Fn::GetAZs
  • Loading branch information
T.J. Corrigan committed Jan 22, 2016
2 parents 558f39a + 2dd4cd9 commit f6cd38e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ object AmazonFunctionCall extends DefaultJsonProtocol {
case r: ParameterRef[_] => implicitly[JsonWriter[ParameterRef[_]#CFBackingType] ].write(r.arguments)
case r: ResourceRef[_] => implicitly[JsonWriter[ResourceRef[_]#CFBackingType] ].write(r.arguments)
case ga: `Fn::GetAtt` => implicitly[JsonWriter[`Fn::GetAtt`#CFBackingType] ].write(ga.arguments)
case azs: `Fn::GetAZs` => implicitly[JsonWriter[`Fn::GetAZs`#CFBackingType] ].write(azs.arguments)
case j: `Fn::Join` => implicitly[JsonWriter[`Fn::Join`#CFBackingType] ].write(j.arguments)
case fim: `Fn::FindInMap`[_] => implicit val foo = MappingRef.formatUnderscore
implicitly[JsonWriter[`Fn::FindInMap`[_]#CFBackingType]].write(fim.arguments)
Expand Down Expand Up @@ -110,6 +111,9 @@ object ResourceRef extends DefaultJsonProtocol {
case class `Fn::GetAtt`(args: Seq[String])
extends AmazonFunctionCall[String]("Fn::GetAtt"){type CFBackingType = Seq[String] ; val arguments = args}

case class `Fn::GetAZs`(region: Token[String])
extends AmazonFunctionCall[Seq[String]]("Fn::GetAZs"){type CFBackingType = Token[String] ; val arguments = region}

case class `Fn::Join`(joinChar: String, toJoin: Seq[Token[String]])
extends AmazonFunctionCall[String]("Fn::Join"){type CFBackingType = (String, Seq[Token[String]]) ; val arguments = (joinChar, toJoin)}

Expand All @@ -122,14 +126,14 @@ case class `Fn::Base64`(toEncode: Token[String])
case class `Fn::Equals`(a: Token[String], b: Token[String])
extends AmazonFunctionCall[String]("Fn::Equals"){type CFBackingType = (Token[String], Token[String]) ; val arguments = (a, b)}

case class `Fn::Not`(fn: Token[String])
extends AmazonFunctionCall[String]("Fn::Not"){type CFBackingType = (Seq[Token[String]]) ; val arguments = Seq(fn)}
case class `Fn::Not`(fn: Token[ConditionRef])
extends AmazonFunctionCall[String]("Fn::Not"){type CFBackingType = (Seq[Token[ConditionRef]]) ; val arguments = Seq(fn)}

case class `Fn::And`(fn: Seq[Token[String]])
extends AmazonFunctionCall[String]("Fn::And"){type CFBackingType = (Seq[Token[String]]) ; val arguments = fn}
case class `Fn::And`(fn: Seq[Token[ConditionRef]])
extends AmazonFunctionCall[String]("Fn::And"){type CFBackingType = (Seq[Token[ConditionRef]]) ; val arguments = fn}

case class `Fn::Or`(fn: Seq[Token[String]])
extends AmazonFunctionCall[String]("Fn::Or"){type CFBackingType = (Seq[Token[String]]) ; val arguments = fn}
case class `Fn::Or`(fn: Seq[Token[ConditionRef]])
extends AmazonFunctionCall[String]("Fn::Or"){type CFBackingType = (Seq[Token[ConditionRef]]) ; val arguments = fn}

case class `Fn::Select`[R: JsonFormat](index: Token[StringBackedInt], listOfObjects: Token[Seq[R]])
extends AmazonFunctionCall[R]("Fn::Select") {
Expand All @@ -138,8 +142,8 @@ case class `Fn::Select`[R: JsonFormat](index: Token[StringBackedInt], listOfObje
def serializeArguments = arguments.toJson
}

case class `Fn::If`[R : JsonFormat](conditionName : Token[String], valIfTrue: Token[R], valIfFalse: Token[R])
extends AmazonFunctionCall[R]("Fn::If"){type CFBackingType = (Token[String], Token[R], Token[R]) ; val arguments = (conditionName, valIfTrue, valIfFalse)
case class `Fn::If`[R : JsonFormat](conditionName : Token[ConditionRef], valIfTrue: Token[R], valIfFalse: Token[R])
extends AmazonFunctionCall[R]("Fn::If"){type CFBackingType = (Token[ConditionRef], Token[R], Token[R]) ; val arguments = (conditionName, valIfTrue, valIfFalse)

def serializeArguments = arguments.toJson
}
Expand Down Expand Up @@ -230,4 +234,4 @@ case object `AWS::NotificationARNs` extends PseudoParameterRef("AWS::Notificatio
case object `AWS::NoValue` extends PseudoParameterRef("AWS::NoValue")
case object `AWS::Region` extends PseudoParameterRef("AWS::Region")
case object `AWS::StackId` extends PseudoParameterRef("AWS::StackId")
case object `AWS::StackName` extends PseudoParameterRef("AWS::StackName")
case object `AWS::StackName` extends PseudoParameterRef("AWS::StackName")
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.monsanto.arch.cloudformation.model

import org.scalatest.{FunSpec, Matchers}
import spray.json._
import DefaultJsonProtocol._

class FnGetAZs_UT extends FunSpec with Matchers {

describe("Fn::GetAZs") {
it("should serialize correctly") {
val p = StringParameter("pAZ")
val c = Condition("cAZ", `Fn::Equals`(ParameterRef(p), ""))
val ps = StringListParameter("s")
val az: Token[String] = `Fn::If`[String](
ConditionRef(c),
`Fn::Select`(StringBackedInt(0), `Fn::GetAZs`(`AWS::Region`)),
ParameterRef(p)
)
val expected = JsObject(
"Fn::If"-> JsArray(
JsString("cAZ"),
JsObject("Fn::Select" -> JsArray(
JsString("0"),
JsObject("Fn::GetAZs" -> JsObject("Ref" -> JsString("AWS::Region")))
)),
JsObject("Ref" -> JsString("pAZ"))
)
)
az.toJson should be(expected)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class FnIf_UT extends FunSpec with Matchers {
)

val test: Token[ResourceRef[`AWS::EC2::SecurityGroup`]] = `Fn::If`[ResourceRef[`AWS::EC2::SecurityGroup`]](
"ServiceELBSSLCertNameIsNotDefined",
ConditionRef(cond),
ResourceRef(gatewayELBSecGroupResource),
ResourceRef(gatewayELBSecGroupResource)
)
Expand All @@ -60,4 +60,4 @@ class FnIf_UT extends FunSpec with Matchers {
test.toJson should be(expected)
}
}
}
}

0 comments on commit f6cd38e

Please sign in to comment.