fix: Correct capacity_reservation_target within launch templates of both EKS and self managed node groups (#1979)

This commit is contained in:
Bryant Biggs
2022-04-02 14:49:25 -04:00
committed by GitHub
parent 6d7245621f
commit 381144e3bb
5 changed files with 18 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
repos: repos:
- repo: https://github.com/antonbabenko/pre-commit-terraform - repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.64.0 rev: v1.64.1
hooks: hooks:
- id: terraform_fmt - id: terraform_fmt
- id: terraform_validate - id: terraform_validate

View File

@@ -49,6 +49,7 @@ Note that this example may create resources which cost money. Run `terraform des
| Name | Type | | Name | Type |
|------|------| |------|------|
| [aws_ec2_capacity_reservation.targeted](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ec2_capacity_reservation) | resource |
| [aws_key_pair.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/key_pair) | resource | | [aws_key_pair.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/key_pair) | resource |
| [aws_kms_key.ebs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) | resource | | [aws_kms_key.ebs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) | resource |
| [aws_kms_key.eks](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) | resource | | [aws_kms_key.eks](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) | resource |

View File

@@ -202,6 +202,12 @@ module "eks" {
instance_metadata_tags = "disabled" instance_metadata_tags = "disabled"
} }
capacity_reservation_specification = {
capacity_reservation_target = {
capacity_reservation_id = aws_ec2_capacity_reservation.targeted.id
}
}
create_iam_role = true create_iam_role = true
iam_role_name = "self-managed-node-group-complete-example" iam_role_name = "self-managed-node-group-complete-example"
iam_role_use_name_prefix = false iam_role_use_name_prefix = false
@@ -407,6 +413,14 @@ resource "aws_kms_key" "ebs" {
policy = data.aws_iam_policy_document.ebs.json policy = data.aws_iam_policy_document.ebs.json
} }
resource "aws_ec2_capacity_reservation" "targeted" {
instance_type = "m6i.large"
instance_platform = "Linux/UNIX"
availability_zone = "${local.region}a"
instance_count = 1
instance_match_criteria = "targeted"
}
# 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 # 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
data "aws_iam_policy_document" "ebs" { data "aws_iam_policy_document" "ebs" {
# Copy of default KMS policy that lets you manage it # Copy of default KMS policy that lets you manage it

View File

@@ -94,7 +94,7 @@ resource "aws_launch_template" "this" {
capacity_reservation_preference = lookup(capacity_reservation_specification.value, "capacity_reservation_preference", null) capacity_reservation_preference = lookup(capacity_reservation_specification.value, "capacity_reservation_preference", null)
dynamic "capacity_reservation_target" { dynamic "capacity_reservation_target" {
for_each = lookup(capacity_reservation_specification.value, "capacity_reservation_target", []) for_each = try([capacity_reservation_specification.value.capacity_reservation_target], [])
content { content {
capacity_reservation_id = lookup(capacity_reservation_target.value, "capacity_reservation_id", null) capacity_reservation_id = lookup(capacity_reservation_target.value, "capacity_reservation_id", null)
} }

View File

@@ -97,7 +97,7 @@ resource "aws_launch_template" "this" {
capacity_reservation_preference = lookup(capacity_reservation_specification.value, "capacity_reservation_preference", null) capacity_reservation_preference = lookup(capacity_reservation_specification.value, "capacity_reservation_preference", null)
dynamic "capacity_reservation_target" { dynamic "capacity_reservation_target" {
for_each = lookup(capacity_reservation_specification.value, "capacity_reservation_target", []) for_each = try([capacity_reservation_specification.value.capacity_reservation_target], [])
content { content {
capacity_reservation_id = lookup(capacity_reservation_target.value, "capacity_reservation_id", null) capacity_reservation_id = lookup(capacity_reservation_target.value, "capacity_reservation_id", null)
} }