From ab052d6183334ec655180feee1dc97d9e33fd2b8 Mon Sep 17 00:00:00 2001 From: dtsai-czi <100375199+dtsai-czi@users.noreply.github.com> Date: Mon, 23 May 2022 11:18:21 -0700 Subject: [PATCH] feat: Enable SSH for Swipe [CCIE-5] (#83) --- main.tf | 1 + .../container_instance_user_data | 8 ------ .../modules/swipe-sfn-batch-queue/main.tf | 28 +++++++++++++++++-- .../swipe-sfn-batch-queue/variables.tf | 9 ++++++ variables.tf | 9 ++++++ version | 2 +- 6 files changed, 45 insertions(+), 12 deletions(-) diff --git a/main.tf b/main.tf index 520576a7..eaa0f8e0 100644 --- a/main.tf +++ b/main.tf @@ -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 { diff --git a/terraform/modules/swipe-sfn-batch-queue/container_instance_user_data b/terraform/modules/swipe-sfn-batch-queue/container_instance_user_data index 74d85a85..4182b812 100644 --- a/terraform/modules/swipe-sfn-batch-queue/container_instance_user_data +++ b/terraform/modules/swipe-sfn-batch-queue/container_instance_user_data @@ -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 ############################################## @@ -39,5 +33,3 @@ crontab -l > /tmp/mycron echo "* * * * * /bin/space-check" > /tmp/mycron crontab /tmp/mycron rm /tmp/mycron - ---==MYBOUNDARY==-- diff --git a/terraform/modules/swipe-sfn-batch-queue/main.tf b/terraform/modules/swipe-sfn-batch-queue/main.tf index c7141bdb..77160a2a 100644 --- a/terraform/modules/swipe-sfn-batch-queue/main.tf +++ b/terraform/modules/swipe-sfn-batch-queue/main.tf @@ -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" { @@ -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" diff --git a/terraform/modules/swipe-sfn-batch-queue/variables.tf b/terraform/modules/swipe-sfn-batch-queue/variables.tf index 0f48e8a6..d6b79b9b 100644 --- a/terraform/modules/swipe-sfn-batch-queue/variables.tf +++ b/terraform/modules/swipe-sfn-batch-queue/variables.tf @@ -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 = [] +} \ No newline at end of file diff --git a/variables.tf b/variables.tf index 1a71f766..90b7481f 100644 --- a/variables.tf +++ b/variables.tf @@ -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 = [] +} \ No newline at end of file diff --git a/version b/version index d2f87e24..21a3d8d5 100644 --- a/version +++ b/version @@ -1 +1 @@ -v0.21.3-beta \ No newline at end of file +v0.22.3-beta