Skip to content

Commit e0c08e9

Browse files
author
Abhinav Khanna
authored
feat(aws_launch_template): parametrize metadata_options (#63)
1 parent 61ac930 commit e0c08e9

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@ Available targets:
288288
| launch\_template\_name | The name (not ID) of a custom launch template to use for the EKS node group. If provided, it must specify the AMI image id. | `string` | `null` | no |
289289
| launch\_template\_version | The version of the specified launch template to use. Defaults to latest version. | `string` | `null` | no |
290290
| max\_size | Maximum number of worker nodes | `number` | n/a | yes |
291+
| metadata\_http\_endpoint | Whether the metadata service is available. Can be enabled or disabled | `string` | `"enabled"` | no |
292+
| metadata\_http\_put\_response\_hop\_limit | The desired HTTP PUT response hop limit for instance metadata requests. The larger the number, the further instance metadata requests can travel. Can be an integer from 1 to 64 | `number` | `2` | no |
293+
| metadata\_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 |
291294
| min\_size | Minimum number of worker nodes | `number` | n/a | yes |
292295
| module\_depends\_on | Can be any value desired. Module will wait for this value to be computed before creating node group. | `any` | `null` | no |
293296
| name | Solution name, e.g. 'app' or 'jenkins' | `string` | `null` | no |

docs/terraform.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@
8282
| launch\_template\_name | The name (not ID) of a custom launch template to use for the EKS node group. If provided, it must specify the AMI image id. | `string` | `null` | no |
8383
| launch\_template\_version | The version of the specified launch template to use. Defaults to latest version. | `string` | `null` | no |
8484
| max\_size | Maximum number of worker nodes | `number` | n/a | yes |
85+
| metadata\_http\_endpoint | Whether the metadata service is available. Can be enabled or disabled | `string` | `"enabled"` | no |
86+
| metadata\_http\_put\_response\_hop\_limit | The desired HTTP PUT response hop limit for instance metadata requests. The larger the number, the further instance metadata requests can travel. Can be an integer from 1 to 64 | `number` | `2` | no |
87+
| metadata\_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 |
8588
| min\_size | Minimum number of worker nodes | `number` | n/a | yes |
8689
| module\_depends\_on | Can be any value desired. Module will wait for this value to be computed before creating node group. | `any` | `null` | no |
8790
| name | Solution name, e.g. 'app' or 'jenkins' | `string` | `null` | no |

launch-template.tf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,12 @@ resource "aws_launch_template" "default" {
9090
# If any containers that you deploy to the node group use the Instance Metadata Service Version 2,
9191
# then make sure to set the Metadata response hop limit to 2 in your launch template.
9292
metadata_options {
93-
http_put_response_hop_limit = 2
9493
# Despite being documented as "Optional", `http_endpoint` is required when `http_put_response_hop_limit` is set.
9594
# We set it to the default setting of "enabled".
96-
http_endpoint = "enabled"
95+
96+
http_endpoint = var.metadata_http_endpoint
97+
http_put_response_hop_limit = var.metadata_http_put_response_hop_limit
98+
http_tokens = var.metadata_http_tokens
9799
}
98100

99101
vpc_security_group_ids = local.launch_template_vpc_security_group_ids

main.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ locals {
22
enabled = module.this.enabled
33

44
# See https://aws.amazon.com/blogs/containers/introducing-launch-template-and-custom-ami-support-in-amazon-eks-managed-node-groups/
5-
features_require_ami = local.enabled && local.need_bootstrap
6-
configured_ami_image_id = var.ami_image_id == null ? "" : var.ami_image_id
7-
need_ami_id = local.enabled ? local.features_require_ami && length(local.configured_ami_image_id) == 0 : false
8-
9-
features_require_launch_template = local.enabled ? length(var.resources_to_tag) > 0 || local.need_userdata || local.features_require_ami : false
5+
features_require_ami = local.enabled && local.need_bootstrap
6+
configured_ami_image_id = var.ami_image_id == null ? "" : var.ami_image_id
7+
need_ami_id = local.enabled ? local.features_require_ami && length(local.configured_ami_image_id) == 0 : false
8+
need_imds_settings = var.metadata_http_endpoint != "enabled" || var.metadata_http_put_response_hop_limit != 1 || var.metadata_http_tokens != "optional"
9+
features_require_launch_template = local.enabled ? length(var.resources_to_tag) > 0 || local.need_userdata || local.features_require_ami || local.need_imds_settings : false
1010

1111
have_ssh_key = var.ec2_ssh_key != null && var.ec2_ssh_key != ""
1212

variables.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,20 @@ variable "launch_template_disk_encryption_kms_key_id" {
279279
description = "Custom KMS Key ID to encrypt EBS volumes on EC2 instances, applicable only if `launch_template_disk_encryption_enabled` is set to true"
280280
}
281281

282+
variable "metadata_http_put_response_hop_limit" {
283+
default = 2
284+
type = number
285+
description = "The desired HTTP PUT response hop limit for instance metadata requests. The larger the number, the further instance metadata requests can travel. Can be an integer from 1 to 64"
286+
}
287+
288+
variable "metadata_http_endpoint" {
289+
default = "enabled"
290+
type = string
291+
description = "Whether the metadata service is available. Can be enabled or disabled"
292+
}
293+
294+
variable "metadata_http_tokens" {
295+
default = "optional"
296+
type = string
297+
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"
298+
}

0 commit comments

Comments
 (0)