From 5db3da4c10f529eb447c1c95dae7e6993f25f178 Mon Sep 17 00:00:00 2001 From: Angel Pizarro Date: Fri, 8 Nov 2024 09:09:56 -0500 Subject: [PATCH 1/3] Added the `launch_template_custom_user_data` variable to the `metaflow-computation` submodule. Addresses issue #99 --- modules/computation/README.md | 1 + modules/computation/ec2.tf | 3 +++ modules/computation/variables.tf | 7 +++++++ 3 files changed, 11 insertions(+) diff --git a/modules/computation/README.md b/modules/computation/README.md index 719b878..e91246d 100644 --- a/modules/computation/README.md +++ b/modules/computation/README.md @@ -21,6 +21,7 @@ To read more, see [the Metaflow docs](https://docs.metaflow.org/metaflow-on-aws/ | [compute\_environment\_max\_vcpus](#input\_compute\_environment\_max\_vcpus) | Maximum VCPUs for Batch Compute Environment [16-96] | `number` | n/a | yes | | [compute\_environment\_min\_vcpus](#input\_compute\_environment\_min\_vcpus) | Minimum VCPUs for Batch Compute Environment [0-16] for EC2 Batch Compute Environment (ignored for Fargate) | `number` | n/a | yes | | [iam\_partition](#input\_iam\_partition) | IAM Partition (Select aws-us-gov for AWS GovCloud, otherwise leave as is) | `string` | `"aws"` | no | +| [launch\_template\_custom\_user\_data](#input\_launch\_template\_custom\_user\_data) | Custom user data script for the launch template provided as a base64-encoded string. | `string` | `null` | no | | [launch\_template\_http\_endpoint](#input\_launch\_template\_http\_endpoint) | Whether the metadata service is available. Can be 'enabled' or 'disabled' | `string` | `"enabled"` | no | | [launch\_template\_http\_put\_response\_hop\_limit](#input\_launch\_template\_http\_put\_response\_hop\_limit) | The desired HTTP PUT response hop limit for instance metadata requests. Can be an integer from 1 to 64 | `number` | `2` | no | | [launch\_template\_http\_tokens](#input\_launch\_template\_http\_tokens) | Whether or not the metadata service requires session tokens, also referred to as Instance Metadata Service Version 2 (IMDSv2). Can be 'optional' or 'required' | `string` | `"optional"` | no | diff --git a/modules/computation/ec2.tf b/modules/computation/ec2.tf index ef40aa4..9dd0313 100644 --- a/modules/computation/ec2.tf +++ b/modules/computation/ec2.tf @@ -34,6 +34,9 @@ resource "aws_launch_template" "cpu" { http_put_response_hop_limit = var.launch_template_http_put_response_hop_limit } + # Supply custom user data as a base64 encoded string. + user_data = var.launch_template_custom_user_data + tags = var.standard_tags } diff --git a/modules/computation/variables.tf b/modules/computation/variables.tf index 92d11ba..b828444 100644 --- a/modules/computation/variables.tf +++ b/modules/computation/variables.tf @@ -102,3 +102,10 @@ variable "launch_template_image_id" { nullable = true default = null } + +variable "launch_template_custom_user_data" { + type = string + description = "Custom user data script for the launch template provided as a base64-encoded string." + nullable = true + default = null +} From 329d9a709ee3f6c40c1cce17fb38351a36c19382 Mon Sep 17 00:00:00 2001 From: Angel Pizarro Date: Mon, 13 Jan 2025 09:36:40 -0500 Subject: [PATCH 2/3] Revised user data to be a string that will be base64 encoded if defined. --- modules/computation/ec2.tf | 7 +++++-- modules/computation/variables.tf | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/computation/ec2.tf b/modules/computation/ec2.tf index 9dd0313..4304d23 100644 --- a/modules/computation/ec2.tf +++ b/modules/computation/ec2.tf @@ -34,8 +34,11 @@ resource "aws_launch_template" "cpu" { http_put_response_hop_limit = var.launch_template_http_put_response_hop_limit } - # Supply custom user data as a base64 encoded string. - user_data = var.launch_template_custom_user_data + # Base64 encode user data for the launch template if it is defined. + # User data must be in MIME multi-part archive format. + # Refer to the AWS Batch user guide for examples. + # https://docs.aws.amazon.com/batch/latest/userguide/launch-templates.html#lt-user-data + user_data = var.launch_template_custom_user_data != null ? base64encode(var.launch_template_custom_user_data ) : null tags = var.standard_tags } diff --git a/modules/computation/variables.tf b/modules/computation/variables.tf index b828444..645be7f 100644 --- a/modules/computation/variables.tf +++ b/modules/computation/variables.tf @@ -105,7 +105,7 @@ variable "launch_template_image_id" { variable "launch_template_custom_user_data" { type = string - description = "Custom user data script for the launch template provided as a base64-encoded string." + description = "Custom user data in MIME multi-part archive format for the launch template. Refer to the AWS Batch user guide for examples at https://docs.aws.amazon.com/batch/latest/userguide/launch-templates.html#lt-user-data" nullable = true default = null } From 40ac104c23a7f927256bc4183a188941def1be8a Mon Sep 17 00:00:00 2001 From: Angel Pizarro Date: Mon, 13 Jan 2025 09:46:29 -0500 Subject: [PATCH 3/3] Updated README with tf docs --- modules/computation/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/computation/README.md b/modules/computation/README.md index e91246d..adf3bc8 100644 --- a/modules/computation/README.md +++ b/modules/computation/README.md @@ -16,12 +16,12 @@ To read more, see [the Metaflow docs](https://docs.metaflow.org/metaflow-on-aws/ | [compute\_environment\_additional\_security\_group\_ids](#input\_compute\_environment\_additional\_security\_group\_ids) | Additional security group ids to apply to the Batch Compute environment | `list(string)` | `[]` | no | | [compute\_environment\_allocation\_strategy](#input\_compute\_environment\_allocation\_strategy) | Allocation strategy for Batch Compute environment (BEST\_FIT, BEST\_FIT\_PROGRESSIVE, SPOT\_CAPACITY\_OPTIMIZED) | `string` | `"BEST_FIT"` | no | | [compute\_environment\_desired\_vcpus](#input\_compute\_environment\_desired\_vcpus) | Desired Starting VCPUs for Batch Compute Environment [0-16] for EC2 Batch Compute Environment (ignored for Fargate) | `number` | n/a | yes | -| [compute\_environment\_egress\_cidr\_blocks](#input\_compute\_environment\_egress\_cidr\_blocks) | CIDR blocks to which egress is allowed from the Batch Compute environment's security group | `list(string)` |
[
"0.0.0.0/0"
]
| no | +| [compute\_environment\_egress\_cidr\_blocks](#input\_compute\_environment\_egress\_cidr\_blocks) | CIDR blocks to which egress is allowed from the Batch Compute environment's security group | `list(string)` |
[
"0.0.0.0/0"
]
| no | | [compute\_environment\_instance\_types](#input\_compute\_environment\_instance\_types) | The instance types for the compute environment as a comma-separated list | `list(string)` | n/a | yes | | [compute\_environment\_max\_vcpus](#input\_compute\_environment\_max\_vcpus) | Maximum VCPUs for Batch Compute Environment [16-96] | `number` | n/a | yes | | [compute\_environment\_min\_vcpus](#input\_compute\_environment\_min\_vcpus) | Minimum VCPUs for Batch Compute Environment [0-16] for EC2 Batch Compute Environment (ignored for Fargate) | `number` | n/a | yes | | [iam\_partition](#input\_iam\_partition) | IAM Partition (Select aws-us-gov for AWS GovCloud, otherwise leave as is) | `string` | `"aws"` | no | -| [launch\_template\_custom\_user\_data](#input\_launch\_template\_custom\_user\_data) | Custom user data script for the launch template provided as a base64-encoded string. | `string` | `null` | no | +| [launch\_template\_custom\_user\_data](#input\_launch\_template\_custom\_user\_data) | Custom user data in MIME multi-part archive format for the launch template. Refer to the AWS Batch user guide for examples at https://docs.aws.amazon.com/batch/latest/userguide/launch-templates.html#lt-user-data | `string` | `null` | no | | [launch\_template\_http\_endpoint](#input\_launch\_template\_http\_endpoint) | Whether the metadata service is available. Can be 'enabled' or 'disabled' | `string` | `"enabled"` | no | | [launch\_template\_http\_put\_response\_hop\_limit](#input\_launch\_template\_http\_put\_response\_hop\_limit) | The desired HTTP PUT response hop limit for instance metadata requests. Can be an integer from 1 to 64 | `number` | `2` | no | | [launch\_template\_http\_tokens](#input\_launch\_template\_http\_tokens) | Whether or not the metadata service requires session tokens, also referred to as Instance Metadata Service Version 2 (IMDSv2). Can be 'optional' or 'required' | `string` | `"optional"` | no |