Skip to content

Commit 9d1acdd

Browse files
authored
Support IMDSv2 in launch template (#43)
* Expose variables for IMDSv2 * Enable http_endpoint * fmt * pre-commit * Enable http endpoint by default * Hop limit defaults to 2
1 parent 1b86971 commit 9d1acdd

File tree

6 files changed

+61
-10
lines changed

6 files changed

+61
-10
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ You can find a more complete example that uses this module but also includes set
107107
| <a name="input_extra_ui_backend_env_vars"></a> [extra\_ui\_backend\_env\_vars](#input\_extra\_ui\_backend\_env\_vars) | Additional environment variables for UI backend container | `map(string)` | `{}` | no |
108108
| <a name="input_extra_ui_static_env_vars"></a> [extra\_ui\_static\_env\_vars](#input\_extra\_ui\_static\_env\_vars) | Additional environment variables for UI static app | `map(string)` | `{}` | no |
109109
| <a name="input_iam_partition"></a> [iam\_partition](#input\_iam\_partition) | IAM Partition (Select aws-us-gov for AWS GovCloud, otherwise leave as is) | `string` | `"aws"` | no |
110+
| <a name="input_launch_template_http_endpoint"></a> [launch\_template\_http\_endpoint](#input\_launch\_template\_http\_endpoint) | Whether the metadata service is available. Can be 'enabled' or 'disabled' | `string` | `"enabled"` | no |
111+
| <a name="input_launch_template_http_put_response_hop_limit"></a> [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 |
112+
| <a name="input_launch_template_http_tokens"></a> [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 |
110113
| <a name="input_metadata_service_container_image"></a> [metadata\_service\_container\_image](#input\_metadata\_service\_container\_image) | Container image for metadata service | `string` | `""` | no |
111114
| <a name="input_resource_prefix"></a> [resource\_prefix](#input\_resource\_prefix) | string prefix for all resources | `string` | `"metaflow"` | no |
112115
| <a name="input_resource_suffix"></a> [resource\_suffix](#input\_resource\_suffix) | string suffix for all resources | `string` | `""` | no |

main.tf

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,19 @@ module "metaflow-computation" {
7575
resource_prefix = local.resource_prefix
7676
resource_suffix = local.resource_suffix
7777

78-
batch_type = var.batch_type
79-
compute_environment_desired_vcpus = var.compute_environment_desired_vcpus
80-
compute_environment_instance_types = var.compute_environment_instance_types
81-
compute_environment_max_vcpus = var.compute_environment_max_vcpus
82-
compute_environment_min_vcpus = var.compute_environment_min_vcpus
83-
compute_environment_egress_cidr_blocks = var.compute_environment_egress_cidr_blocks
84-
iam_partition = var.iam_partition
85-
metaflow_vpc_id = var.vpc_id
86-
subnet1_id = var.subnet1_id
87-
subnet2_id = var.subnet2_id
78+
batch_type = var.batch_type
79+
compute_environment_desired_vcpus = var.compute_environment_desired_vcpus
80+
compute_environment_instance_types = var.compute_environment_instance_types
81+
compute_environment_max_vcpus = var.compute_environment_max_vcpus
82+
compute_environment_min_vcpus = var.compute_environment_min_vcpus
83+
compute_environment_egress_cidr_blocks = var.compute_environment_egress_cidr_blocks
84+
iam_partition = var.iam_partition
85+
metaflow_vpc_id = var.vpc_id
86+
subnet1_id = var.subnet1_id
87+
subnet2_id = var.subnet2_id
88+
launch_template_http_endpoint = var.launch_template_http_endpoint
89+
launch_template_http_tokens = var.launch_template_http_tokens
90+
launch_template_http_put_response_hop_limit = var.launch_template_http_put_response_hop_limit
8891

8992
standard_tags = var.tags
9093
}

modules/computation/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ To read more, see [the Metaflow docs](https://docs.metaflow.org/metaflow-on-aws/
1919
| <a name="input_compute_environment_max_vcpus"></a> [compute\_environment\_max\_vcpus](#input\_compute\_environment\_max\_vcpus) | Maximum VCPUs for Batch Compute Environment [16-96] | `number` | n/a | yes |
2020
| <a name="input_compute_environment_min_vcpus"></a> [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 |
2121
| <a name="input_iam_partition"></a> [iam\_partition](#input\_iam\_partition) | IAM Partition (Select aws-us-gov for AWS GovCloud, otherwise leave as is) | `string` | `"aws"` | no |
22+
| <a name="input_launch_template_http_endpoint"></a> [launch\_template\_http\_endpoint](#input\_launch\_template\_http\_endpoint) | Whether the metadata service is available. Can be 'enabled' or 'disabled' | `string` | `"enabled"` | no |
23+
| <a name="input_launch_template_http_put_response_hop_limit"></a> [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 |
24+
| <a name="input_launch_template_http_tokens"></a> [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 |
2225
| <a name="input_metaflow_vpc_id"></a> [metaflow\_vpc\_id](#input\_metaflow\_vpc\_id) | ID of the Metaflow VPC this SageMaker notebook instance is to be deployed in | `string` | n/a | yes |
2326
| <a name="input_resource_prefix"></a> [resource\_prefix](#input\_resource\_prefix) | Prefix given to all AWS resources to differentiate between applications | `string` | n/a | yes |
2427
| <a name="input_resource_suffix"></a> [resource\_suffix](#input\_resource\_suffix) | Suffix given to all AWS resources to differentiate between environment and workspace | `string` | n/a | yes |

modules/computation/ec2.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ resource "aws_launch_template" "cpu" {
2525
}
2626
}
2727

28+
metadata_options {
29+
http_endpoint = var.launch_template_http_endpoint
30+
http_tokens = var.launch_template_http_tokens
31+
http_put_response_hop_limit = var.launch_template_http_put_response_hop_limit
32+
}
33+
2834
tags = var.standard_tags
2935
}
3036

modules/computation/variables.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,21 @@ variable "subnet2_id" {
6565
type = string
6666
description = "The second private subnet used for redundancy"
6767
}
68+
69+
variable "launch_template_http_endpoint" {
70+
type = string
71+
description = "Whether the metadata service is available. Can be 'enabled' or 'disabled'"
72+
default = "enabled"
73+
}
74+
75+
variable "launch_template_http_tokens" {
76+
type = string
77+
description = "Whether or not the metadata service requires session tokens, also referred to as Instance Metadata Service Version 2 (IMDSv2). Can be 'optional' or 'required'"
78+
default = "optional"
79+
}
80+
81+
variable "launch_template_http_put_response_hop_limit" {
82+
type = number
83+
description = "The desired HTTP PUT response hop limit for instance metadata requests. Can be an integer from 1 to 64"
84+
default = 2
85+
}

variables.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,24 @@ variable "compute_environment_egress_cidr_blocks" {
6767
description = "CIDR blocks to which egress is allowed from the Batch Compute environment's security group"
6868
}
6969

70+
variable "launch_template_http_endpoint" {
71+
type = string
72+
description = "Whether the metadata service is available. Can be 'enabled' or 'disabled'"
73+
default = "enabled"
74+
}
75+
76+
variable "launch_template_http_tokens" {
77+
type = string
78+
description = "Whether or not the metadata service requires session tokens, also referred to as Instance Metadata Service Version 2 (IMDSv2). Can be 'optional' or 'required'"
79+
default = "optional"
80+
}
81+
82+
variable "launch_template_http_put_response_hop_limit" {
83+
type = number
84+
description = "The desired HTTP PUT response hop limit for instance metadata requests. Can be an integer from 1 to 64"
85+
default = 2
86+
}
87+
7088
variable "iam_partition" {
7189
type = string
7290
default = "aws"

0 commit comments

Comments
 (0)