Skip to content

Commit

Permalink
Merge pull request #101 from aniketbhatnagar/Security-Group-Ports-Par…
Browse files Browse the repository at this point in the history
…ameterization

Ports in Security groups can now be parameterized
  • Loading branch information
T.J. Corrigan committed Jun 15, 2016
2 parents 37f9df1 + 6c03f5a commit 80d2bd5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,8 @@ case class `AWS::EC2::SecurityGroupIngress`(
name: String,
GroupId: Token[ResourceRef[`AWS::EC2::SecurityGroup`]],
IpProtocol: String,
FromPort: String,
ToPort: String,
FromPort: Token[String],
ToPort: Token[String],
CidrIp: Option[Token[CidrBlock]] = None, // either CidrIp or SourceSecurityGroupId required
SourceSecurityGroupId: Option[Token[ResourceRef[`AWS::EC2::SecurityGroup`]]] = None, // either CidrIp or SourceSecurityGroupId required
override val Condition: Option[ConditionRef] = None
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.monsanto.arch.cloudformation.model.resource

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

class EC2_UT extends FunSpec with Matchers {

Expand Down Expand Up @@ -185,4 +185,42 @@ class EC2_UT extends FunSpec with Matchers {
}
}

describe("AWS::EC2::SecurityGroupIngress") {
val securityGroupParam = `AWS::EC2::SecurityGroup_Parameter`("testSGParam", "testSGParam")
val ingres = `AWS::EC2::SecurityGroupIngress`(
name = "Test Ingress",
GroupId = ParameterRef(securityGroupParam),
IpProtocol = "TCP",
FromPort = "80",
ToPort = "80",
CidrIp = Some(CidrBlock(192, 168, 1, 2, 32))
)

it("should write valid SecurityGroupIngress"){
ingres.toJson shouldEqual JsObject(
"name" -> JsString("Test Ingress"),
"CidrIp" -> JsString("192.168.1.2/32"),
"GroupId" -> JsObject("Ref" -> JsString("testSGParam")),
"ToPort" -> JsString("80"),
"FromPort" -> JsString("80"),
"IpProtocol" -> JsString("TCP")
)
}

it("should write valid SecurityGroupIngress when parameterized"){
val portParam = StringParameter("portParam")
val ingresParameterized = ingres.copy(
FromPort = ParameterRef(portParam),
ToPort = ParameterRef(portParam)
)
ingresParameterized.toJson shouldEqual JsObject(
"name" -> JsString("Test Ingress"),
"CidrIp" -> JsString("192.168.1.2/32"),
"GroupId" -> JsObject("Ref" -> JsString("testSGParam")),
"ToPort" -> JsObject("Ref" -> JsString("portParam")),
"FromPort" -> JsObject("Ref" -> JsString("portParam")),
"IpProtocol" -> JsString("TCP")
)
}
}
}

0 comments on commit 80d2bd5

Please sign in to comment.