Skip to content

Commit

Permalink
Allow requiring IMDSv2 on Node Group instances
Browse files Browse the repository at this point in the history
When creating a new Node Group, one can specify if they need EC2
instances to enforce IMDSv2.

This is a SOC2 compliance requirement.
  • Loading branch information
clarissalimab committed Oct 3, 2024
1 parent 8f8c1f4 commit 6429a90
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions aws/cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module "node_groups" {
capacity_type = each.value.capacity_type
cluster = module.eks_cluster.instance
instance_types = each.value.instance_types
enforce_imdsv2 = each.value.enforce_imdsv2
labels = var.labels
max_size = each.value.max_size
max_unavailable = each.value.max_unavailable
Expand Down
17 changes: 17 additions & 0 deletions aws/cluster/modules/eks-node-group/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ resource "aws_eks_node_group" "this" {
node_role_arn = var.role.arn
subnet_ids = [each.value.id]

dynamic "launch_template" {
for_each = var.enforce_imdsv2 ? [aws_launch_template.this[0]] : []

content {
id = launch_template.value.id
version = launch_template.value.latest_version
}
}

scaling_config {
desired_size = local.min_size_per_node_group
max_size = local.max_size_per_node_group
Expand All @@ -31,6 +40,14 @@ resource "aws_eks_node_group" "this" {
}
}

resource "aws_launch_template" "this" {
count = var.enforce_imdsv2 ? 1 : 0

metadata_options {
http_tokens = "required"
}
}

locals {
min_size_per_node_group = ceil(var.min_size / 2)
max_size_per_node_group = ceil(var.max_size / 2)
Expand Down
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 @@ -69,3 +69,9 @@ variable "max_unavailable" {
description = "Maximum number of nodes that can be unavailable during a rolling update"
default = 1
}

variable "enforce_imdsv2" {
type = bool
description = "Whether to enforce IMDSv2 on the launch template"
default = false
}
1 change: 1 addition & 0 deletions aws/cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ variable "node_groups" {
type = map(object({
capacity_type = optional(string, "ON_DEMAND")
instance_types = list(string),
enforce_imdsv2 = optional(bool, false)
max_size = number
max_unavailable = optional(number, 3)
min_size = number
Expand Down

0 comments on commit 6429a90

Please sign in to comment.