Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modeled Autoscaling EBS parameters #28

Merged
merged 2 commits into from
Sep 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,65 @@ case class `AWS::AutoScaling::LaunchConfiguration`(
SecurityGroups: Seq[Token[ResourceRef[`AWS::EC2::SecurityGroup`]]],
UserData: `Fn::Base64`,
IamInstanceProfile: Option[Token[ResourceRef[`AWS::IAM::InstanceProfile`]]] = None,
BlockDeviceMappings: Option[Seq[BlockDeviceMapping]] = None,
override val Condition: Option[ConditionRef] = None,
override val DependsOn : Option[Seq[String]] = None
) extends Resource[`AWS::AutoScaling::LaunchConfiguration`] {
def when(newCondition: Option[ConditionRef] = Condition) = copy(Condition = newCondition)
}

object `AWS::AutoScaling::LaunchConfiguration` extends DefaultJsonProtocol {
implicit val format: JsonFormat[`AWS::AutoScaling::LaunchConfiguration`] = jsonFormat9(`AWS::AutoScaling::LaunchConfiguration`.apply)
implicit val format: JsonFormat[`AWS::AutoScaling::LaunchConfiguration`] = jsonFormat10(`AWS::AutoScaling::LaunchConfiguration`.apply)
}
case class BlockDeviceMapping private(
DeviceName: Token[String],
Ebs: Option[AutoScalingEBS] = None,
NoDevice: Option[Token[Boolean]] = None,
VirtualName: Option[Token[String]] = None
)
object BlockDeviceMapping extends DefaultJsonProtocol {
implicit val format: JsonFormat[BlockDeviceMapping] = jsonFormat4(BlockDeviceMapping.apply)

def ebs(
DeviceName: Token[String],
Ebs: AutoScalingEBS,
NoDevice: Option[Token[Boolean]] = None
) = BlockDeviceMapping(DeviceName, Some(Ebs), NoDevice, None)

def virtual(
DeviceName: Token[String],
VirtualName: Token[String],
NoDevice: Option[Token[Boolean]] = None
) = BlockDeviceMapping(DeviceName, None, NoDevice, Some(VirtualName))
}

case class AutoScalingEBS(
DeleteOnTermination: Option[Token[Boolean]] = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure a Token of a Boolean is allowed?

Iops: Option[Token[Int]] = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here for Token of Int.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Token[Int] works fine -- I've used the one on VolumeSize already. It's used numerous places in CFTG. Token[Boolean] should work too -- I haven't tested it though since I don't know why you'd even want to use that parameter, really. It was already being used in other Autoscaling parameters.

SnapshotId: Option[Token[String]] = None,
VolumeSize: Option[Token[Int]] = None,
VolumeType: Option[VolumeType] = None
)
object AutoScalingEBS extends DefaultJsonProtocol {
implicit val format: JsonFormat[AutoScalingEBS] = jsonFormat5(AutoScalingEBS.apply)
}

sealed trait VolumeType
object VolumeType extends DefaultJsonProtocol{
case object Standard extends VolumeType
case object IO1 extends VolumeType
case object GP2 extends VolumeType
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just name the object the lower case versions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are issues if you want to do pattern matching on lower case names -- it treats them as variables by default if they start with lowercase. Granted, I don't expect much pattern matching on these, but it still seemed best to avoid that issue.


implicit val format: JsonFormat[VolumeType] = new JsonFormat[VolumeType] {
override def write(obj: VolumeType): JsValue = JsString(obj.toString.toLowerCase())

override def read(json: JsValue): VolumeType = json.toString() match {
case "standard" => Standard
case "io1" => IO1
case "gp2" => GP2
}
}
}
case class `AWS::AutoScaling::ScalingPolicy`(
name: String,
AdjustmentType: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,20 @@ trait Autoscaling {
userData: `Fn::Base64`,
iam: Option[Token[ResourceRef[`AWS::IAM::InstanceProfile`]]] = None,
condition: Option[ConditionRef] = None,
dependsOn: Option[Seq[String]] = None
dependsOn: Option[Seq[String]] = None,
blockDevices: Option[Seq[BlockDeviceMapping]] = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically we keep Condition and DependsOn last, but putting BlockDevices last allows backward compatibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ddgenome I can change it if you want, but I do know that microservices-vpc doesn't name parameters when it uses this, so it'd need to be updated when we move to this release of cftg. Let me know your preference.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they do use named parameters now in microservices-vpc, but it's probably better to keep backwards compatibility.

)(implicit vpc: `AWS::EC2::VPC`) =
SecurityGroupRoutable from `AWS::AutoScaling::LaunchConfiguration`(
name = name,
ImageId = image,
InstanceType = instanceType,
KeyName = keyName,
SecurityGroups = sgs,
UserData = userData,
IamInstanceProfile = iam,
Condition = condition,
DependsOn = dependsOn
name = name,
ImageId = image,
InstanceType = instanceType,
KeyName = keyName,
SecurityGroups = sgs,
UserData = userData,
IamInstanceProfile = iam,
Condition = condition,
DependsOn = dependsOn,
BlockDeviceMappings = blockDevices
)

def asg(
Expand All @@ -226,7 +228,8 @@ trait Autoscaling {
userData: `Fn::Base64`,
iam: Option[Token[ResourceRef[`AWS::IAM::InstanceProfile`]]] = None,
condition: Option[ConditionRef] = None,
dependsOn: Option[Seq[String]] = None
dependsOn: Option[Seq[String]] = None,
blockDevices: Option[Seq[BlockDeviceMapping]] = None
)(
minSize: Int,
maxSize: Int,
Expand All @@ -241,7 +244,7 @@ trait Autoscaling {
val asgName = baseName + "AutoScale"

val launchConfigSGR @ SecurityGroupRoutable(aLaunchConfig, _, _) =
launchConfig(baseName, image, instanceType, keyName, sgs, userData, iam, condition, dependsOn)
launchConfig(baseName, image, instanceType, keyName, sgs, userData, iam, condition, dependsOn, blockDevices)

val asg = `AWS::AutoScaling::AutoScalingGroup`(
name = asgName,
Expand Down