Skip to content

Commit

Permalink
Pass in custom metadata options to the eks launch template
Browse files Browse the repository at this point in the history
  • Loading branch information
OlamideOl1 committed Sep 25, 2024
1 parent a094ef5 commit 4d60e81
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
20 changes: 17 additions & 3 deletions aws/cluster/modules/eks-node-group/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ resource "aws_eks_node_group" "this" {
subnet_ids = [each.value.id]

dynamic "launch_template" {
for_each = var.user_data != null ? [aws_launch_template.this[0]] : []
for_each = var.metadata_options != {} ? [aws_launch_template.this[0]] : []

content {
id = launch_template.value.id
Expand Down Expand Up @@ -40,10 +40,22 @@ resource "aws_eks_node_group" "this" {
}
}

# resource "aws_launch_template" "this" {
# count = var.user_data != null ? 1 : 0

# user_data = base64encode(var.user_data)
# }

resource "aws_launch_template" "this" {
count = var.user_data != null ? 1 : 0
count = var.metadata_options != {} ? 1 : 0

user_data = base64encode(var.user_data)
metadata_options {
http_endpoint = lookup(var.metadata_options, "http_endpoint", "enabled")
http_tokens = lookup(var.metadata_options, "http_tokens", "optional")
http_put_response_hop_limit = lookup(var.metadata_options, "htthttp_put_response_hop_limit", "1")
http_protocol_ipv6 = lookup(var.metadata_options, "http_protocol_ipv6", "disabled")
instance_metadata_tags = lookup(var.metadata_options, "instance_metadata_tags", "disabled")
}
}

locals {
Expand All @@ -54,4 +66,6 @@ locals {
var.subnets[*].availability_zone,
var.subnets
)


}
6 changes: 6 additions & 0 deletions aws/cluster/modules/eks-node-group/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,9 @@ variable "user_data" {
description = "Optional user data script for the launch template"
default = null # Default to an empty string if no user data is provided
}

variable "metadata_options" {
type = map(string)
description = "Customize the metadata options for the cluster nodes"
default = {}
}

0 comments on commit 4d60e81

Please sign in to comment.