Skip to content

Commit

Permalink
feat: Enable SSH for Swipe [CCIE-5] (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
dtsai-czi authored May 23, 2022
1 parent 9228a04 commit ab052d6
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 12 deletions.
1 change: 1 addition & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module "batch_queue" {
on_demand_max_vcpus = var.on_demand_max_vcpus
tags = var.tags
imdsv2_policy = var.imdsv2_policy
user_data_parts = var.user_data_parts
}

locals {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="==MYBOUNDARY=="

--==MYBOUNDARY==
Content-Type: text/cloud-boothook; charset="us-ascii"

#!/bin/bash -ex

##############################################
Expand Down Expand Up @@ -39,5 +33,3 @@ crontab -l > /tmp/mycron
echo "* * * * * /bin/space-check" > /tmp/mycron
crontab /tmp/mycron
rm /tmp/mycron

--==MYBOUNDARY==--
28 changes: 25 additions & 3 deletions terraform/modules/swipe-sfn-batch-queue/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
locals {
launch_template_user_data = replace(file("${path.module}/container_instance_user_data"), "MINIWDL_DIR", var.miniwdl_dir)
launch_template_user_data_hash = md5(local.launch_template_user_data)
launch_template_swipe_user_data_filename = "${path.module}/container_instance_user_data"
launch_template_swipe_user_data = replace(file(local.launch_template_swipe_user_data_filename), "MINIWDL_DIR", var.miniwdl_dir)
launch_template_swipe_user_data_parts = [{
filename = local.launch_template_swipe_user_data_filename,
content_type = "text/cloud-boothook; charset=\"us-ascii\"",
content = local.launch_template_swipe_user_data
}]

launch_template_all_user_data_parts = concat(local.launch_template_swipe_user_data_parts, var.user_data_parts)
launch_template_user_data_hash = md5(jsonencode(local.launch_template_all_user_data_parts))
}

data "template_cloudinit_config" "user_data_merge" {
gzip = false

dynamic "part" {
for_each = local.launch_template_all_user_data_parts
content {
filename = part.value["filename"]
content_type = part.value["content_type"]
content = part.value["content"]
merge_type = "list(append)+dict(no_replace,recurse_list)"
}
}
}

data "aws_ssm_parameter" "swipe_batch_ami" {
Expand Down Expand Up @@ -68,8 +90,8 @@ resource "aws_launch_template" "swipe_batch_main" {
# not recognize this change. We bind the launch template name to user data contents here, so any changes to user data
# will cause the whole launch template to be replaced, forcing the compute environment to pick up the changes.
name = "${var.app_name}-batch-main-${local.launch_template_user_data_hash}"
user_data = base64encode(local.launch_template_user_data)
tags = var.tags
user_data = data.template_cloudinit_config.user_data_merge.rendered

metadata_options {
http_endpoint = "enabled"
Expand Down
9 changes: 9 additions & 0 deletions terraform/modules/swipe-sfn-batch-queue/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,12 @@ variable "imdsv2_policy" {
type = string
default = "optional"
}

variable "user_data_parts" {
type = list(object({
filename = string
content_type = string
content = string
}))
default = []
}
9 changes: 9 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,12 @@ variable "metrics_schedule" {
type = string
default = "rate(1 minute)"
}

variable "user_data_parts" {
type = list(object({
filename = string
content_type = string
content = string
}))
default = []
}
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.21.3-beta
v0.22.3-beta

0 comments on commit ab052d6

Please sign in to comment.