mirror of
https://github.com/ysoftdevs/terraform-aws-eks.git
synced 2026-04-30 04:14:41 +02:00
feat!: Replace the use of aws-auth configmap with EKS cluster access entry (#2858)
* feat: Replace `resolve_conflicts` with `resolve_conflicts_on_create`/`delete`; raise MSV of AWS provider to `v5.0` to support * fix: Replace dynamic DNS suffix for `sts:AssumeRole` API calls for static suffix * feat: Add module tag * feat: Align Karpenter permissions with Karpenter v1beta1/v0.32 permissions from upstream * refactor: Move `aws-auth` ConfigMap functionality to its own sub-module * chore: Update examples * feat: Add state `moved` block for Karpenter Pod Identity role re-name * fix: Correct variable `create` description * feat: Add support for cluster access entries * chore: Bump MSV of Terraform to `1.3` * fix: Replace defunct kubectl provider with an updated forked equivalent * chore: Update and validate examples for access entry; clean up provider usage * docs: Correct double redundant variable descriptions * feat: Add support for Cloudwatch log group class argument * fix: Update usage tag placement, fix Karpenter event spelling, add upcoming changes section to upgrade guide * feat: Update Karpenter module to generalize naming used and align policy with the upstream Karpenter policy * feat: Add native support for Windows based managed nodegroups similar to AL2 and Bottlerocket * feat: Update self-managed nodegroup module to use latest features of ASG * docs: Update and simplify docs * fix: Correct variable description for AMI types * fix: Update upgrade guide with changes; rename Karpenter controller resource names to support migrating for users * docs: Complete upgrade guide docs for migration and changes applied * Update examples/karpenter/README.md Co-authored-by: Anton Babenko <anton@antonbabenko.com> * Update examples/outposts/README.md Co-authored-by: Anton Babenko <anton@antonbabenko.com> * Update modules/karpenter/README.md Co-authored-by: Anton Babenko <anton@antonbabenko.com> --------- Co-authored-by: Anton Babenko <anton@antonbabenko.com>
This commit is contained in:
@@ -42,14 +42,14 @@ module "self_managed_node_group" {
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
|
||||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.57 |
|
||||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
|
||||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.34 |
|
||||
|
||||
## Providers
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.57 |
|
||||
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.34 |
|
||||
|
||||
## Modules
|
||||
|
||||
@@ -63,6 +63,7 @@ module "self_managed_node_group" {
|
||||
|------|------|
|
||||
| [aws_autoscaling_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_group) | resource |
|
||||
| [aws_autoscaling_schedule.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_schedule) | resource |
|
||||
| [aws_eks_access_entry.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/eks_access_entry) | resource |
|
||||
| [aws_iam_instance_profile.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_instance_profile) | resource |
|
||||
| [aws_iam_role.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
|
||||
| [aws_iam_role_policy_attachment.additional](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
|
||||
@@ -93,6 +94,7 @@ module "self_managed_node_group" {
|
||||
| <a name="input_context"></a> [context](#input\_context) | Reserved | `string` | `null` | no |
|
||||
| <a name="input_cpu_options"></a> [cpu\_options](#input\_cpu\_options) | The CPU options for the instance | `map(string)` | `{}` | no |
|
||||
| <a name="input_create"></a> [create](#input\_create) | Determines whether to create self managed node group or not | `bool` | `true` | no |
|
||||
| <a name="input_create_access_entry"></a> [create\_access\_entry](#input\_create\_access\_entry) | Determines whether an access entry is created for the IAM role used by the nodegroup | `bool` | `true` | no |
|
||||
| <a name="input_create_autoscaling_group"></a> [create\_autoscaling\_group](#input\_create\_autoscaling\_group) | Determines whether to create autoscaling group or not | `bool` | `true` | no |
|
||||
| <a name="input_create_iam_instance_profile"></a> [create\_iam\_instance\_profile](#input\_create\_iam\_instance\_profile) | Determines whether an IAM instance profile is created or to use an existing IAM instance profile | `bool` | `true` | no |
|
||||
| <a name="input_create_launch_template"></a> [create\_launch\_template](#input\_create\_launch\_template) | Determines whether to create launch template or not | `bool` | `true` | no |
|
||||
@@ -116,6 +118,7 @@ module "self_managed_node_group" {
|
||||
| <a name="input_hibernation_options"></a> [hibernation\_options](#input\_hibernation\_options) | The hibernation options for the instance | `map(string)` | `{}` | no |
|
||||
| <a name="input_iam_instance_profile_arn"></a> [iam\_instance\_profile\_arn](#input\_iam\_instance\_profile\_arn) | Amazon Resource Name (ARN) of an existing IAM instance profile that provides permissions for the node group. Required if `create_iam_instance_profile` = `false` | `string` | `null` | no |
|
||||
| <a name="input_iam_role_additional_policies"></a> [iam\_role\_additional\_policies](#input\_iam\_role\_additional\_policies) | Additional policies to be added to the IAM role | `map(string)` | `{}` | no |
|
||||
| <a name="input_iam_role_arn"></a> [iam\_role\_arn](#input\_iam\_role\_arn) | ARN of the IAM role used by the instance profile. Required when `create_access_entry = true` and `create_iam_instance_profile = false` | `string` | `null` | no |
|
||||
| <a name="input_iam_role_attach_cni_policy"></a> [iam\_role\_attach\_cni\_policy](#input\_iam\_role\_attach\_cni\_policy) | Whether to attach the `AmazonEKS_CNI_Policy`/`AmazonEKS_CNI_IPv6_Policy` IAM policy to the IAM IAM role. WARNING: If set `false` the permissions must be assigned to the `aws-node` DaemonSet pods via another method or nodes will not be able to join the cluster | `bool` | `true` | no |
|
||||
| <a name="input_iam_role_description"></a> [iam\_role\_description](#input\_iam\_role\_description) | Description of the role | `string` | `null` | no |
|
||||
| <a name="input_iam_role_name"></a> [iam\_role\_name](#input\_iam\_role\_name) | Name to use on IAM role created | `string` | `null` | no |
|
||||
@@ -125,6 +128,7 @@ module "self_managed_node_group" {
|
||||
| <a name="input_iam_role_use_name_prefix"></a> [iam\_role\_use\_name\_prefix](#input\_iam\_role\_use\_name\_prefix) | Determines whether cluster IAM role name (`iam_role_name`) is used as a prefix | `bool` | `true` | no |
|
||||
| <a name="input_initial_lifecycle_hooks"></a> [initial\_lifecycle\_hooks](#input\_initial\_lifecycle\_hooks) | One or more Lifecycle Hooks to attach to the Auto Scaling Group before instances are launched. The syntax is exactly the same as the separate `aws_autoscaling_lifecycle_hook` resource, without the `autoscaling_group_name` attribute. Please note that this will only work when creating a new Auto Scaling Group. For all other use-cases, please use `aws_autoscaling_lifecycle_hook` resource | `list(map(string))` | `[]` | no |
|
||||
| <a name="input_instance_initiated_shutdown_behavior"></a> [instance\_initiated\_shutdown\_behavior](#input\_instance\_initiated\_shutdown\_behavior) | Shutdown behavior for the instance. Can be `stop` or `terminate`. (Default: `stop`) | `string` | `null` | no |
|
||||
| <a name="input_instance_maintenance_policy"></a> [instance\_maintenance\_policy](#input\_instance\_maintenance\_policy) | If this block is configured, add a instance maintenance policy to the specified Auto Scaling group | `any` | `{}` | no |
|
||||
| <a name="input_instance_market_options"></a> [instance\_market\_options](#input\_instance\_market\_options) | The market (purchasing) option for the instance | `any` | `{}` | no |
|
||||
| <a name="input_instance_refresh"></a> [instance\_refresh](#input\_instance\_refresh) | If this block is configured, start an Instance Refresh when this Auto Scaling Group is updated | `any` | <pre>{<br> "preferences": {<br> "min_healthy_percentage": 66<br> },<br> "strategy": "Rolling"<br>}</pre> | no |
|
||||
| <a name="input_instance_requirements"></a> [instance\_requirements](#input\_instance\_requirements) | The attribute requirements for the type of instance. If present then `instance_type` cannot be present | `any` | `{}` | no |
|
||||
@@ -178,6 +182,7 @@ module "self_managed_node_group" {
|
||||
|
||||
| Name | Description |
|
||||
|------|-------------|
|
||||
| <a name="output_access_entry_arn"></a> [access\_entry\_arn](#output\_access\_entry\_arn) | Amazon Resource Name (ARN) of the Access Entry |
|
||||
| <a name="output_autoscaling_group_arn"></a> [autoscaling\_group\_arn](#output\_autoscaling\_group\_arn) | The ARN for this autoscaling group |
|
||||
| <a name="output_autoscaling_group_availability_zones"></a> [autoscaling\_group\_availability\_zones](#output\_autoscaling\_group\_availability\_zones) | The availability zones of the autoscaling group |
|
||||
| <a name="output_autoscaling_group_default_cooldown"></a> [autoscaling\_group\_default\_cooldown](#output\_autoscaling\_group\_default\_cooldown) | Time between a scaling activity and the succeeding scaling activity |
|
||||
|
||||
@@ -438,6 +438,15 @@ resource "aws_autoscaling_group" "this" {
|
||||
}
|
||||
}
|
||||
|
||||
dynamic "instance_maintenance_policy" {
|
||||
for_each = length(var.instance_maintenance_policy) > 0 ? [var.instance_maintenance_policy] : []
|
||||
|
||||
content {
|
||||
min_healthy_percentage = instance_maintenance_policy.value.min_healthy_percentage
|
||||
max_healthy_percentage = instance_maintenance_policy.value.max_healthy_percentage
|
||||
}
|
||||
}
|
||||
|
||||
dynamic "instance_refresh" {
|
||||
for_each = length(var.instance_refresh) > 0 ? [var.instance_refresh] : []
|
||||
|
||||
@@ -446,11 +455,14 @@ resource "aws_autoscaling_group" "this" {
|
||||
for_each = try([instance_refresh.value.preferences], [])
|
||||
|
||||
content {
|
||||
checkpoint_delay = try(preferences.value.checkpoint_delay, null)
|
||||
checkpoint_percentages = try(preferences.value.checkpoint_percentages, null)
|
||||
instance_warmup = try(preferences.value.instance_warmup, null)
|
||||
min_healthy_percentage = try(preferences.value.min_healthy_percentage, null)
|
||||
skip_matching = try(preferences.value.skip_matching, null)
|
||||
checkpoint_delay = try(preferences.value.checkpoint_delay, null)
|
||||
checkpoint_percentages = try(preferences.value.checkpoint_percentages, null)
|
||||
instance_warmup = try(preferences.value.instance_warmup, null)
|
||||
max_healthy_percentage = try(preferences.value.max_healthy_percentage, null)
|
||||
min_healthy_percentage = try(preferences.value.min_healthy_percentage, null)
|
||||
scale_in_protected_instances = try(preferences.value.scale_in_protected_instances, null)
|
||||
skip_matching = try(preferences.value.skip_matching, null)
|
||||
standby_instances = try(preferences.value.standby_instances, null)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -686,28 +698,6 @@ resource "aws_autoscaling_group" "this" {
|
||||
}
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Autoscaling group schedule
|
||||
################################################################################
|
||||
|
||||
resource "aws_autoscaling_schedule" "this" {
|
||||
for_each = { for k, v in var.schedules : k => v if var.create && var.create_schedule }
|
||||
|
||||
scheduled_action_name = each.key
|
||||
autoscaling_group_name = aws_autoscaling_group.this[0].name
|
||||
|
||||
min_size = try(each.value.min_size, null)
|
||||
max_size = try(each.value.max_size, null)
|
||||
desired_capacity = try(each.value.desired_size, null)
|
||||
start_time = try(each.value.start_time, null)
|
||||
end_time = try(each.value.end_time, null)
|
||||
time_zone = try(each.value.time_zone, null)
|
||||
|
||||
# [Minute] [Hour] [Day_of_Month] [Month_of_Year] [Day_of_Week]
|
||||
# Cron examples: https://crontab.guru/examples.html
|
||||
recurrence = try(each.value.recurrence, null)
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# IAM Role
|
||||
################################################################################
|
||||
@@ -727,7 +717,7 @@ data "aws_iam_policy_document" "assume_role_policy" {
|
||||
|
||||
principals {
|
||||
type = "Service"
|
||||
identifiers = ["ec2.${data.aws_partition.current.dns_suffix}"]
|
||||
identifiers = ["ec2.amazonaws.com"]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -780,3 +770,39 @@ resource "aws_iam_instance_profile" "this" {
|
||||
create_before_destroy = true
|
||||
}
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Access Entry
|
||||
################################################################################
|
||||
|
||||
resource "aws_eks_access_entry" "this" {
|
||||
count = var.create && var.create_access_entry ? 1 : 0
|
||||
|
||||
cluster_name = var.cluster_name
|
||||
principal_arn = var.create_iam_instance_profile ? aws_iam_role.this[0].arn : var.iam_role_arn
|
||||
type = var.platform == "windows" ? "EC2_WINDOWS" : "EC2_LINUX"
|
||||
|
||||
tags = var.tags
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Autoscaling group schedule
|
||||
################################################################################
|
||||
|
||||
resource "aws_autoscaling_schedule" "this" {
|
||||
for_each = { for k, v in var.schedules : k => v if var.create && var.create_schedule }
|
||||
|
||||
scheduled_action_name = each.key
|
||||
autoscaling_group_name = aws_autoscaling_group.this[0].name
|
||||
|
||||
min_size = try(each.value.min_size, null)
|
||||
max_size = try(each.value.max_size, null)
|
||||
desired_capacity = try(each.value.desired_size, null)
|
||||
start_time = try(each.value.start_time, null)
|
||||
end_time = try(each.value.end_time, null)
|
||||
time_zone = try(each.value.time_zone, null)
|
||||
|
||||
# [Minute] [Hour] [Day_of_Month] [Month_of_Year] [Day_of_Week]
|
||||
# Cron examples: https://crontab.guru/examples.html
|
||||
recurrence = try(each.value.recurrence, null)
|
||||
}
|
||||
|
||||
@@ -81,15 +81,6 @@ output "autoscaling_group_vpc_zone_identifier" {
|
||||
value = try(aws_autoscaling_group.this[0].vpc_zone_identifier, null)
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Autoscaling Group Schedule
|
||||
################################################################################
|
||||
|
||||
output "autoscaling_group_schedule_arns" {
|
||||
description = "ARNs of autoscaling group schedules"
|
||||
value = { for k, v in aws_autoscaling_schedule.this : k => v.arn }
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# IAM Role
|
||||
################################################################################
|
||||
@@ -128,6 +119,24 @@ output "iam_instance_profile_unique" {
|
||||
value = try(aws_iam_instance_profile.this[0].unique_id, null)
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Access Entry
|
||||
################################################################################
|
||||
|
||||
output "access_entry_arn" {
|
||||
description = "Amazon Resource Name (ARN) of the Access Entry"
|
||||
value = try(aws_eks_access_entry.this[0].access_entry_arn, null)
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Autoscaling Group Schedule
|
||||
################################################################################
|
||||
|
||||
output "autoscaling_group_schedule_arns" {
|
||||
description = "ARNs of autoscaling group schedules"
|
||||
value = { for k, v in aws_autoscaling_schedule.this : k => v.arn }
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Additional
|
||||
################################################################################
|
||||
|
||||
@@ -476,6 +476,12 @@ variable "initial_lifecycle_hooks" {
|
||||
default = []
|
||||
}
|
||||
|
||||
variable "instance_maintenance_policy" {
|
||||
description = "If this block is configured, add a instance maintenance policy to the specified Auto Scaling group"
|
||||
type = any
|
||||
default = {}
|
||||
}
|
||||
|
||||
variable "instance_refresh" {
|
||||
description = "If this block is configured, start an Instance Refresh when this Auto Scaling Group is updated"
|
||||
type = any
|
||||
@@ -517,22 +523,6 @@ variable "autoscaling_group_tags" {
|
||||
default = {}
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Autoscaling group schedule
|
||||
################################################################################
|
||||
|
||||
variable "create_schedule" {
|
||||
description = "Determines whether to create autoscaling group schedule or not"
|
||||
type = bool
|
||||
default = true
|
||||
}
|
||||
|
||||
variable "schedules" {
|
||||
description = "Map of autoscaling group schedule to create"
|
||||
type = map(any)
|
||||
default = {}
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# IAM Role
|
||||
################################################################################
|
||||
@@ -602,3 +592,35 @@ variable "iam_role_tags" {
|
||||
type = map(string)
|
||||
default = {}
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Access Entry
|
||||
################################################################################
|
||||
|
||||
variable "create_access_entry" {
|
||||
description = "Determines whether an access entry is created for the IAM role used by the nodegroup"
|
||||
type = bool
|
||||
default = true
|
||||
}
|
||||
|
||||
variable "iam_role_arn" {
|
||||
description = "ARN of the IAM role used by the instance profile. Required when `create_access_entry = true` and `create_iam_instance_profile = false`"
|
||||
type = string
|
||||
default = null
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Autoscaling group schedule
|
||||
################################################################################
|
||||
|
||||
variable "create_schedule" {
|
||||
description = "Determines whether to create autoscaling group schedule or not"
|
||||
type = bool
|
||||
default = true
|
||||
}
|
||||
|
||||
variable "schedules" {
|
||||
description = "Map of autoscaling group schedule to create"
|
||||
type = map(any)
|
||||
default = {}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
terraform {
|
||||
required_version = ">= 1.0"
|
||||
required_version = ">= 1.3"
|
||||
|
||||
required_providers {
|
||||
aws = {
|
||||
source = "hashicorp/aws"
|
||||
version = ">= 4.57"
|
||||
version = ">= 5.34"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user