Skip to content

Commit 3031631

Browse files
feat: Add supprot for creating placement group for managed node group (#2959)
Co-authored-by: Bryant Biggs <[email protected]>
1 parent 0be0a99 commit 3031631

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

modules/eks-managed-node-group/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ module "eks_managed_node_group" {
120120
| <a name="input_create"></a> [create](#input\_create) | Determines whether to create EKS managed node group or not | `bool` | `true` | no |
121121
| <a name="input_create_iam_role"></a> [create\_iam\_role](#input\_create\_iam\_role) | Determines whether an IAM role is created or to use an existing IAM role | `bool` | `true` | no |
122122
| <a name="input_create_launch_template"></a> [create\_launch\_template](#input\_create\_launch\_template) | Determines whether to create a launch template or not. If set to `false`, EKS will use its own default launch template | `bool` | `true` | no |
123+
| <a name="input_create_placement_group"></a> [create\_placement\_group](#input\_create\_placement\_group) | Determines whether a placement group is created & used by the nodegroup | `bool` | `false` | no |
123124
| <a name="input_create_schedule"></a> [create\_schedule](#input\_create\_schedule) | Determines whether to create autoscaling group schedule or not | `bool` | `true` | no |
124125
| <a name="input_credit_specification"></a> [credit\_specification](#input\_credit\_specification) | Customize the credit specification of the instance | `map(string)` | `{}` | no |
125126
| <a name="input_desired_size"></a> [desired\_size](#input\_desired\_size) | Desired number of instances/nodes | `number` | `1` | no |
@@ -162,6 +163,7 @@ module "eks_managed_node_group" {
162163
| <a name="input_name"></a> [name](#input\_name) | Name of the EKS managed node group | `string` | `""` | no |
163164
| <a name="input_network_interfaces"></a> [network\_interfaces](#input\_network\_interfaces) | Customize network interfaces to be attached at instance boot time | `list(any)` | `[]` | no |
164165
| <a name="input_placement"></a> [placement](#input\_placement) | The placement of the instance | `map(string)` | `{}` | no |
166+
| <a name="input_placement_group_strategy"></a> [placement\_group\_strategy](#input\_placement\_group\_strategy) | The placement group strategy | `string` | `"cluster"` | no |
165167
| <a name="input_platform"></a> [platform](#input\_platform) | Identifies if the OS platform is `bottlerocket` or `linux` based; `windows` is not supported | `string` | `"linux"` | no |
166168
| <a name="input_post_bootstrap_user_data"></a> [post\_bootstrap\_user\_data](#input\_post\_bootstrap\_user\_data) | User data that is appended to the user data script after of the EKS bootstrap script. Not used when `platform` = `bottlerocket` | `string` | `""` | no |
167169
| <a name="input_pre_bootstrap_user_data"></a> [pre\_bootstrap\_user\_data](#input\_pre\_bootstrap\_user\_data) | User data that is injected into the user data script ahead of the EKS bootstrap script. Not used when `platform` = `bottlerocket` | `string` | `""` | no |

modules/eks-managed-node-group/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ locals {
6060
launch_template_name = coalesce(var.launch_template_name, "${var.name}-eks-node-group")
6161
security_group_ids = compact(concat([var.cluster_primary_security_group_id], var.vpc_security_group_ids))
6262

63-
placement = var.create && var.enable_efa_support ? { group_name = aws_placement_group.this[0].name } : var.placement
63+
placement = var.create && (var.enable_efa_support || var.create_placement_group) ? { group_name = aws_placement_group.this[0].name } : var.placement
6464
}
6565

6666
resource "aws_launch_template" "this" {
@@ -526,10 +526,10 @@ resource "aws_iam_role_policy_attachment" "additional" {
526526
################################################################################
527527

528528
resource "aws_placement_group" "this" {
529-
count = var.create && var.enable_efa_support ? 1 : 0
529+
count = var.create && (var.enable_efa_support || var.create_placement_group) ? 1 : 0
530530

531531
name = "${var.cluster_name}-${var.name}"
532-
strategy = "cluster"
532+
strategy = var.placement_group_strategy
533533

534534
tags = var.tags
535535
}

modules/eks-managed-node-group/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,18 @@ variable "placement" {
276276
default = {}
277277
}
278278

279+
variable "create_placement_group" {
280+
description = "Determines whether a placement group is created & used by the nodegroup"
281+
type = bool
282+
default = false
283+
}
284+
285+
variable "placement_group_strategy" {
286+
description = "The placement group strategy"
287+
type = string
288+
default = "cluster"
289+
}
290+
279291
variable "private_dns_name_options" {
280292
description = "The options for the instance hostname. The default values are inherited from the subnet"
281293
type = map(string)

node_groups.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,8 @@ module "eks_managed_node_group" {
369369
metadata_options = try(each.value.metadata_options, var.eks_managed_node_group_defaults.metadata_options, local.metadata_options)
370370
enable_monitoring = try(each.value.enable_monitoring, var.eks_managed_node_group_defaults.enable_monitoring, true)
371371
enable_efa_support = try(each.value.enable_efa_support, var.eks_managed_node_group_defaults.enable_efa_support, false)
372+
create_placement_group = try(each.value.create_placement_group, var.eks_managed_node_group_defaults.create_placement_group, false)
373+
placement_group_strategy = try(each.value.placement_group_strategy, var.eks_managed_node_group_defaults.placement_group_strategy, "cluster")
372374
network_interfaces = try(each.value.network_interfaces, var.eks_managed_node_group_defaults.network_interfaces, [])
373375
placement = try(each.value.placement, var.eks_managed_node_group_defaults.placement, {})
374376
maintenance_options = try(each.value.maintenance_options, var.eks_managed_node_group_defaults.maintenance_options, {})

0 commit comments

Comments
 (0)