Skip to content

Commit 23ad497

Browse files
authored
feat: IMDSv2 metadata configuration in Launch Templates (#938)
NOTES: Addition of the IMDSv2 metadata configuration block to Launch Templates will cause a diff to be generated for existing Launch Templates on first Terraform apply. The defaults match existing behaviour.
1 parent b0ebef6 commit 23ad497

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a
135135
| Name | Version |
136136
|------|---------|
137137
| terraform | >= 0.12.9 |
138-
| aws | >= 2.52.0 |
138+
| aws | >= 2.55.0 |
139139
| kubernetes | >= 1.11.1 |
140140
| local | >= 1.4 |
141141
| null | >= 2.1 |
@@ -146,7 +146,7 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a
146146

147147
| Name | Version |
148148
|------|---------|
149-
| aws | >= 2.52.0 |
149+
| aws | >= 2.55.0 |
150150
| kubernetes | >= 1.11.1 |
151151
| local | >= 1.4 |
152152
| null | >= 2.1 |

local.tf

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,18 @@ locals {
7676
platform = "linux" # Platform of workers. either "linux" or "windows"
7777
additional_ebs_volumes = [] # A list of additional volumes to be attached to the instances on this Auto Scaling group. Each volume should be an object with the following: block_device_name (required), volume_size, volume_type, iops, encrypted, kms_key_id (only on launch-template), delete_on_termination. Optional values are grabbed from root volume or from defaults
7878
# Settings for launch templates
79-
root_block_device_name = data.aws_ami.eks_worker.root_device_name # Root device name for workers. If non is provided, will assume default AMI was used.
80-
root_kms_key_id = "" # The KMS key to use when encrypting the root storage device
81-
launch_template_version = "$Latest" # The lastest version of the launch template to use in the autoscaling group
82-
launch_template_placement_tenancy = "default" # The placement tenancy for instances
83-
launch_template_placement_group = null # The name of the placement group into which to launch the instances, if any.
84-
root_encrypted = false # Whether the volume should be encrypted or not
85-
eni_delete = true # Delete the Elastic Network Interface (ENI) on termination (if set to false you will have to manually delete before destroying)
86-
cpu_credits = "standard" # T2/T3 unlimited mode, can be 'standard' or 'unlimited'. Used 'standard' mode as default to avoid paying higher costs
87-
market_type = null
79+
root_block_device_name = data.aws_ami.eks_worker.root_device_name # Root device name for workers. If non is provided, will assume default AMI was used.
80+
root_kms_key_id = "" # The KMS key to use when encrypting the root storage device
81+
launch_template_version = "$Latest" # The lastest version of the launch template to use in the autoscaling group
82+
launch_template_placement_tenancy = "default" # The placement tenancy for instances
83+
launch_template_placement_group = null # The name of the placement group into which to launch the instances, if any.
84+
root_encrypted = false # Whether the volume should be encrypted or not
85+
eni_delete = true # Delete the Elastic Network Interface (ENI) on termination (if set to false you will have to manually delete before destroying)
86+
cpu_credits = "standard" # T2/T3 unlimited mode, can be 'standard' or 'unlimited'. Used 'standard' mode as default to avoid paying higher costs
87+
market_type = null
88+
metadata_http_endpoint = "enabled" # The state of the metadata service: enabled, disabled.
89+
metadata_http_tokens = "optional" # If session tokens are required: optional, required.
90+
metadata_http_put_response_hop_limit = null # The desired HTTP PUT response hop limit for instance metadata requests.
8891
# Settings for launch templates with mixed instances policy
8992
override_instance_types = ["m5.large", "m5a.large", "m5d.large", "m5ad.large"] # A list of override instance types for mixed instances policy
9093
on_demand_allocation_strategy = null # Strategy to use when launching on-demand instances. Valid values: prioritized.

versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ terraform {
22
required_version = ">= 0.12.9"
33

44
required_providers {
5-
aws = ">= 2.52.0"
5+
aws = ">= 2.55.0"
66
local = ">= 1.4"
77
null = ">= 2.1"
88
template = ">= 2.1"

workers_launch_template.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,24 @@ resource "aws_launch_template" "workers_launch_template" {
278278
)
279279
)
280280

281+
metadata_options {
282+
http_endpoint = lookup(
283+
var.worker_groups_launch_template[count.index],
284+
"metadata_http_endpoint",
285+
local.workers_group_defaults["metadata_http_endpoint"],
286+
)
287+
http_tokens = lookup(
288+
var.worker_groups_launch_template[count.index],
289+
"metadata_http_tokens",
290+
local.workers_group_defaults["metadata_http_tokens"],
291+
)
292+
http_put_response_hop_limit = lookup(
293+
var.worker_groups_launch_template[count.index],
294+
"metadata_http_put_response_hop_limit",
295+
local.workers_group_defaults["metadata_http_put_response_hop_limit"],
296+
)
297+
}
298+
281299
credit_specification {
282300
cpu_credits = lookup(
283301
var.worker_groups_launch_template[count.index],

0 commit comments

Comments
 (0)