in app/housekeeping/utils/PackerEC2Client.scala [18:52]
private def hasTag(instance: Instance, key: String, value: String): Boolean =
instance.getTags.asScala.exists(tag =>
tag.getKey == key && tag.getValue == value
)
def getBakeInstance(bakeId: BakeId): Option[Instance] = {
// Filters here are base on the instance tags that are set in PackerBuildConfigGenerator.
val request = new DescribeInstancesRequest()
.withFilters(
new Filter("tag:AmigoStage", List(amigoStage).asJava),
new Filter("tag:Stage", List(PackerBuildConfigGenerator.stage).asJava),
new Filter("tag:Stack", List(PackerBuildConfigGenerator.stack).asJava),
new Filter("tag:BakeId", List(bakeId.toString).asJava),
new Filter("instance-state-name", List("running", "stopped").asJava)
)
underlying
.describeInstances(request)
.getReservations
.asScala
.flatMap(_.getInstances.asScala)
.find { instance =>
hasTag(
instance,
key = "Stage",
value = PackerBuildConfigGenerator.stage
) &&
hasTag(
instance,
key = "Stack",
value = PackerBuildConfigGenerator.stack
) &&
hasTag(instance, key = "BakeId", value = bakeId.toString)
}
}