Skip to content

Commit 381144e

Browse files
authored
fix: Correct capacity_reservation_target within launch templates of both EKS and self managed node groups (#1979)
1 parent 6d72456 commit 381144e

5 files changed

Lines changed: 18 additions & 3 deletions

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.64.0
3+
rev: v1.64.1
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_validate

examples/self_managed_node_group/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Note that this example may create resources which cost money. Run `terraform des
4949

5050
| Name | Type |
5151
|------|------|
52+
| [aws_ec2_capacity_reservation.targeted](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ec2_capacity_reservation) | resource |
5253
| [aws_key_pair.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/key_pair) | resource |
5354
| [aws_kms_key.ebs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) | resource |
5455
| [aws_kms_key.eks](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) | resource |

examples/self_managed_node_group/main.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,12 @@ module "eks" {
202202
instance_metadata_tags = "disabled"
203203
}
204204

205+
capacity_reservation_specification = {
206+
capacity_reservation_target = {
207+
capacity_reservation_id = aws_ec2_capacity_reservation.targeted.id
208+
}
209+
}
210+
205211
create_iam_role = true
206212
iam_role_name = "self-managed-node-group-complete-example"
207213
iam_role_use_name_prefix = false
@@ -407,6 +413,14 @@ resource "aws_kms_key" "ebs" {
407413
policy = data.aws_iam_policy_document.ebs.json
408414
}
409415

416+
resource "aws_ec2_capacity_reservation" "targeted" {
417+
instance_type = "m6i.large"
418+
instance_platform = "Linux/UNIX"
419+
availability_zone = "${local.region}a"
420+
instance_count = 1
421+
instance_match_criteria = "targeted"
422+
}
423+
410424
# This policy is required for the KMS key used for EKS root volumes, so the cluster is allowed to enc/dec/attach encrypted EBS volumes
411425
data "aws_iam_policy_document" "ebs" {
412426
# Copy of default KMS policy that lets you manage it

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ resource "aws_launch_template" "this" {
9494
capacity_reservation_preference = lookup(capacity_reservation_specification.value, "capacity_reservation_preference", null)
9595

9696
dynamic "capacity_reservation_target" {
97-
for_each = lookup(capacity_reservation_specification.value, "capacity_reservation_target", [])
97+
for_each = try([capacity_reservation_specification.value.capacity_reservation_target], [])
9898
content {
9999
capacity_reservation_id = lookup(capacity_reservation_target.value, "capacity_reservation_id", null)
100100
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ resource "aws_launch_template" "this" {
9797
capacity_reservation_preference = lookup(capacity_reservation_specification.value, "capacity_reservation_preference", null)
9898

9999
dynamic "capacity_reservation_target" {
100-
for_each = lookup(capacity_reservation_specification.value, "capacity_reservation_target", [])
100+
for_each = try([capacity_reservation_specification.value.capacity_reservation_target], [])
101101
content {
102102
capacity_reservation_id = lookup(capacity_reservation_target.value, "capacity_reservation_id", null)
103103
}

0 commit comments

Comments
 (0)