mirror of
https://github.com/terraform-aws-modules/terraform-aws-eks.git
synced 2025-09-09 19:32:58 +08:00
feat!: Upgrade min AWS provider and Terraform versions to 6.0 and 1.5.7 respectively (#3412)
* feat!: Upgrade min AWS provider and Terraform versions to `6.0` and `1.5.7` respectively * fix: Remove deprecated arguments in AWS v6.0 provider, upgrade Helm provider to v3.0, bump VPC module to v6.0 * fix: Remove `aws-auth` sub-module * fix: Remove `platform` and `cluster_service_ipv4_cidr` variables from `user-data` sub-module * fix: Resolve all marked `todos` that have been accumulated * fix: Set default `http_put_response_hop_limit` to `1` * fix: Remove IRSA support from Karpenter sub-module * fix: Avoid making GET requests from data sources unless absolutely necessary * feat: Add variable optional attribute definitions * feat: Bump KMS key module version to latest, add remaining variable attribute definitions * fix: Remove `cluster_` prefix from variable names to better match the underlying API * fix: Move all EFA logic to the nodegroup itself * fix: Remove arguments that do not make sense in EKS * fix: Updates from plan validation * fix: Remove more self-managed node group attributes that are commonly not used in EKS clusters * fix: Remove data plane compute `*_defaults` variables that do not work with variable optional attributes * fix: Ignore changes to `bootstrap_self_managed_addons` to aid in upgrade * feat: Add support for `region` argument on relevant resources * feat: Initial pass on upgrade guide * fix: Updates from testing and validating EKS managed node group * fix: Updates from testing and validating self-managed node group * docs: Ensure addon ussage documented is aligned * feat: Switch to dualstack OIDC issuer URL * feat: Allow sourcing over overriding the Karpenter assume role policy * fix: Use `Bool` instead of `StringEquals` for DenyHTTP queue policy * fix: Correct use of `nullable` and default value propagation
This commit is contained in:
@@ -85,14 +85,14 @@ module "karpenter" {
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.2 |
|
||||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.95, < 6.0.0 |
|
||||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.5.7 |
|
||||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 6.0 |
|
||||
|
||||
## Providers
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.95, < 6.0.0 |
|
||||
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 6.0 |
|
||||
|
||||
## Modules
|
||||
|
||||
@@ -121,8 +121,6 @@ No modules.
|
||||
| [aws_iam_policy_document.controller_assume_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
|
||||
| [aws_iam_policy_document.node_assume_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
|
||||
| [aws_iam_policy_document.queue](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
|
||||
| [aws_iam_policy_document.v033](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
|
||||
| [aws_iam_policy_document.v1](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
|
||||
| [aws_partition.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/partition) | data source |
|
||||
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
|
||||
|
||||
@@ -139,27 +137,23 @@ No modules.
|
||||
| <a name="input_create_iam_role"></a> [create\_iam\_role](#input\_create\_iam\_role) | Determines whether an IAM role is created | `bool` | `true` | no |
|
||||
| <a name="input_create_instance_profile"></a> [create\_instance\_profile](#input\_create\_instance\_profile) | Whether to create an IAM instance profile | `bool` | `false` | no |
|
||||
| <a name="input_create_node_iam_role"></a> [create\_node\_iam\_role](#input\_create\_node\_iam\_role) | Determines whether an IAM role is created or to use an existing IAM role | `bool` | `true` | no |
|
||||
| <a name="input_create_pod_identity_association"></a> [create\_pod\_identity\_association](#input\_create\_pod\_identity\_association) | Determines whether to create pod identity association | `bool` | `false` | no |
|
||||
| <a name="input_enable_irsa"></a> [enable\_irsa](#input\_enable\_irsa) | Determines whether to enable support for IAM role for service accounts | `bool` | `false` | no |
|
||||
| <a name="input_enable_pod_identity"></a> [enable\_pod\_identity](#input\_enable\_pod\_identity) | Determines whether to enable support for EKS pod identity | `bool` | `true` | no |
|
||||
| <a name="input_create_pod_identity_association"></a> [create\_pod\_identity\_association](#input\_create\_pod\_identity\_association) | Determines whether to create pod identity association | `bool` | `true` | no |
|
||||
| <a name="input_enable_spot_termination"></a> [enable\_spot\_termination](#input\_enable\_spot\_termination) | Determines whether to enable native spot termination handling | `bool` | `true` | no |
|
||||
| <a name="input_enable_v1_permissions"></a> [enable\_v1\_permissions](#input\_enable\_v1\_permissions) | Determines whether to enable permissions suitable for v1+ (`true`) or for v0.33.x-v0.37.x (`false`) | `bool` | `false` | no |
|
||||
| <a name="input_iam_policy_description"></a> [iam\_policy\_description](#input\_iam\_policy\_description) | IAM policy description | `string` | `"Karpenter controller IAM policy"` | no |
|
||||
| <a name="input_iam_policy_name"></a> [iam\_policy\_name](#input\_iam\_policy\_name) | Name of the IAM policy | `string` | `"KarpenterController"` | no |
|
||||
| <a name="input_iam_policy_path"></a> [iam\_policy\_path](#input\_iam\_policy\_path) | Path of the IAM policy | `string` | `"/"` | no |
|
||||
| <a name="input_iam_policy_statements"></a> [iam\_policy\_statements](#input\_iam\_policy\_statements) | A list of IAM policy [statements](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document#statement) - used for adding specific IAM permissions as needed | `any` | `[]` | no |
|
||||
| <a name="input_iam_policy_statements"></a> [iam\_policy\_statements](#input\_iam\_policy\_statements) | A list of IAM policy [statements](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document#statement) - used for adding specific IAM permissions as needed | <pre>list(object({<br/> sid = optional(string)<br/> actions = optional(list(string))<br/> not_actions = optional(list(string))<br/> effect = optional(string)<br/> resources = optional(list(string))<br/> not_resources = optional(list(string))<br/> principals = optional(list(object({<br/> type = string<br/> identifiers = list(string)<br/> })))<br/> not_principals = optional(list(object({<br/> type = string<br/> identifiers = list(string)<br/> })))<br/> condition = optional(list(object({<br/> test = string<br/> values = list(string)<br/> variable = string<br/> })))<br/> }))</pre> | `null` | no |
|
||||
| <a name="input_iam_policy_use_name_prefix"></a> [iam\_policy\_use\_name\_prefix](#input\_iam\_policy\_use\_name\_prefix) | Determines whether the name of the IAM policy (`iam_policy_name`) is used as a prefix | `bool` | `true` | no |
|
||||
| <a name="input_iam_role_description"></a> [iam\_role\_description](#input\_iam\_role\_description) | IAM role description | `string` | `"Karpenter controller IAM role"` | no |
|
||||
| <a name="input_iam_role_max_session_duration"></a> [iam\_role\_max\_session\_duration](#input\_iam\_role\_max\_session\_duration) | Maximum API session duration in seconds between 3600 and 43200 | `number` | `null` | no |
|
||||
| <a name="input_iam_role_name"></a> [iam\_role\_name](#input\_iam\_role\_name) | Name of the IAM role | `string` | `"KarpenterController"` | no |
|
||||
| <a name="input_iam_role_override_assume_policy_documents"></a> [iam\_role\_override\_assume\_policy\_documents](#input\_iam\_role\_override\_assume\_policy\_documents) | A list of IAM policy documents to override the default assume role policy document for the Karpenter controller IAM role | `list(string)` | `[]` | no |
|
||||
| <a name="input_iam_role_path"></a> [iam\_role\_path](#input\_iam\_role\_path) | Path of the IAM role | `string` | `"/"` | no |
|
||||
| <a name="input_iam_role_permissions_boundary_arn"></a> [iam\_role\_permissions\_boundary\_arn](#input\_iam\_role\_permissions\_boundary\_arn) | Permissions boundary ARN to use for the IAM role | `string` | `null` | no |
|
||||
| <a name="input_iam_role_policies"></a> [iam\_role\_policies](#input\_iam\_role\_policies) | Policies to attach to the IAM role in `{'static_name' = 'policy_arn'}` format | `map(string)` | `{}` | no |
|
||||
| <a name="input_iam_role_tags"></a> [iam\_role\_tags](#input\_iam\_role\_tags) | A map of additional tags to add the the IAM role | `map(any)` | `{}` | no |
|
||||
| <a name="input_iam_role_source_assume_policy_documents"></a> [iam\_role\_source\_assume\_policy\_documents](#input\_iam\_role\_source\_assume\_policy\_documents) | A list of IAM policy documents to use as a source for the assume role policy document for the Karpenter controller IAM role | `list(string)` | `[]` | no |
|
||||
| <a name="input_iam_role_tags"></a> [iam\_role\_tags](#input\_iam\_role\_tags) | A map of additional tags to add the the IAM role | `map(string)` | `{}` | no |
|
||||
| <a name="input_iam_role_use_name_prefix"></a> [iam\_role\_use\_name\_prefix](#input\_iam\_role\_use\_name\_prefix) | Determines whether the name of the IAM role (`iam_role_name`) is used as a prefix | `bool` | `true` | no |
|
||||
| <a name="input_irsa_assume_role_condition_test"></a> [irsa\_assume\_role\_condition\_test](#input\_irsa\_assume\_role\_condition\_test) | Name of the [IAM condition operator](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition_operators.html) to evaluate when assuming the role | `string` | `"StringEquals"` | no |
|
||||
| <a name="input_irsa_namespace_service_accounts"></a> [irsa\_namespace\_service\_accounts](#input\_irsa\_namespace\_service\_accounts) | List of `namespace:serviceaccount`pairs to use in trust policy for IAM role for service accounts | `list(string)` | <pre>[<br/> "karpenter:karpenter"<br/>]</pre> | no |
|
||||
| <a name="input_irsa_oidc_provider_arn"></a> [irsa\_oidc\_provider\_arn](#input\_irsa\_oidc\_provider\_arn) | OIDC provider arn used in trust policy for IAM role for service accounts | `string` | `""` | no |
|
||||
| <a name="input_namespace"></a> [namespace](#input\_namespace) | Namespace to associate with the Karpenter Pod Identity | `string` | `"kube-system"` | no |
|
||||
| <a name="input_node_iam_role_additional_policies"></a> [node\_iam\_role\_additional\_policies](#input\_node\_iam\_role\_additional\_policies) | Additional policies to be added to the IAM role | `map(string)` | `{}` | no |
|
||||
| <a name="input_node_iam_role_arn"></a> [node\_iam\_role\_arn](#input\_node\_iam\_role\_arn) | Existing IAM role ARN for the IAM instance profile. Required if `create_iam_role` is set to `false` | `string` | `null` | no |
|
||||
@@ -175,6 +169,7 @@ No modules.
|
||||
| <a name="input_queue_kms_master_key_id"></a> [queue\_kms\_master\_key\_id](#input\_queue\_kms\_master\_key\_id) | The ID of an AWS-managed customer master key (CMK) for Amazon SQS or a custom CMK | `string` | `null` | no |
|
||||
| <a name="input_queue_managed_sse_enabled"></a> [queue\_managed\_sse\_enabled](#input\_queue\_managed\_sse\_enabled) | Boolean to enable server-side encryption (SSE) of message content with SQS-owned encryption keys | `bool` | `true` | no |
|
||||
| <a name="input_queue_name"></a> [queue\_name](#input\_queue\_name) | Name of the SQS queue | `string` | `null` | no |
|
||||
| <a name="input_region"></a> [region](#input\_region) | Region where the resource(s) will be managed. Defaults to the Region set in the provider configuration | `string` | `null` | no |
|
||||
| <a name="input_rule_name_prefix"></a> [rule\_name\_prefix](#input\_rule\_name\_prefix) | Prefix used for all event bridge rules | `string` | `"Karpenter"` | no |
|
||||
| <a name="input_service_account"></a> [service\_account](#input\_service\_account) | Service account to associate with the Karpenter Pod Identity | `string` | `"karpenter"` | no |
|
||||
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no |
|
||||
|
||||
+43
-57
@@ -1,12 +1,20 @@
|
||||
data "aws_region" "current" {}
|
||||
data "aws_partition" "current" {}
|
||||
data "aws_caller_identity" "current" {}
|
||||
data "aws_region" "current" {
|
||||
count = var.create ? 1 : 0
|
||||
|
||||
region = var.region
|
||||
}
|
||||
data "aws_partition" "current" {
|
||||
count = var.create ? 1 : 0
|
||||
}
|
||||
data "aws_caller_identity" "current" {
|
||||
count = var.create ? 1 : 0
|
||||
}
|
||||
|
||||
locals {
|
||||
account_id = data.aws_caller_identity.current.account_id
|
||||
dns_suffix = data.aws_partition.current.dns_suffix
|
||||
partition = data.aws_partition.current.partition
|
||||
region = data.aws_region.current.name
|
||||
account_id = try(data.aws_caller_identity.current[0].account_id, "")
|
||||
dns_suffix = try(data.aws_partition.current[0].dns_suffix, "")
|
||||
partition = try(data.aws_partition.current[0].partition, "")
|
||||
region = try(data.aws_region.current[0].region, "")
|
||||
}
|
||||
|
||||
################################################################################
|
||||
@@ -14,54 +22,26 @@ locals {
|
||||
################################################################################
|
||||
|
||||
locals {
|
||||
create_iam_role = var.create && var.create_iam_role
|
||||
irsa_oidc_provider_url = replace(var.irsa_oidc_provider_arn, "/^(.*provider/)/", "")
|
||||
create_iam_role = var.create && var.create_iam_role
|
||||
}
|
||||
|
||||
data "aws_iam_policy_document" "controller_assume_role" {
|
||||
count = local.create_iam_role ? 1 : 0
|
||||
|
||||
override_policy_documents = var.iam_role_override_assume_policy_documents
|
||||
source_policy_documents = var.iam_role_source_assume_policy_documents
|
||||
|
||||
# Pod Identity
|
||||
dynamic "statement" {
|
||||
for_each = var.enable_pod_identity ? [1] : []
|
||||
statement {
|
||||
sid = "PodIdentity"
|
||||
actions = [
|
||||
"sts:AssumeRole",
|
||||
"sts:TagSession",
|
||||
]
|
||||
|
||||
content {
|
||||
actions = [
|
||||
"sts:AssumeRole",
|
||||
"sts:TagSession",
|
||||
]
|
||||
|
||||
principals {
|
||||
type = "Service"
|
||||
identifiers = ["pods.eks.amazonaws.com"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# IAM Roles for Service Accounts (IRSA)
|
||||
dynamic "statement" {
|
||||
for_each = var.enable_irsa ? [1] : []
|
||||
|
||||
content {
|
||||
actions = ["sts:AssumeRoleWithWebIdentity"]
|
||||
|
||||
principals {
|
||||
type = "Federated"
|
||||
identifiers = [var.irsa_oidc_provider_arn]
|
||||
}
|
||||
|
||||
condition {
|
||||
test = var.irsa_assume_role_condition_test
|
||||
variable = "${local.irsa_oidc_provider_url}:sub"
|
||||
values = [for sa in var.irsa_namespace_service_accounts : "system:serviceaccount:${sa}"]
|
||||
}
|
||||
|
||||
# https://aws.amazon.com/premiumsupport/knowledge-center/eks-troubleshoot-oidc-and-irsa/?nc1=h_ls
|
||||
condition {
|
||||
test = var.irsa_assume_role_condition_test
|
||||
variable = "${local.irsa_oidc_provider_url}:aud"
|
||||
values = ["sts.amazonaws.com"]
|
||||
}
|
||||
principals {
|
||||
type = "Service"
|
||||
identifiers = ["pods.eks.amazonaws.com"]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,12 +62,6 @@ resource "aws_iam_role" "controller" {
|
||||
tags = merge(var.tags, var.iam_role_tags)
|
||||
}
|
||||
|
||||
data "aws_iam_policy_document" "controller" {
|
||||
count = local.create_iam_role ? 1 : 0
|
||||
|
||||
source_policy_documents = var.enable_v1_permissions ? [data.aws_iam_policy_document.v1[0].json] : [data.aws_iam_policy_document.v033[0].json]
|
||||
}
|
||||
|
||||
resource "aws_iam_policy" "controller" {
|
||||
count = local.create_iam_role ? 1 : 0
|
||||
|
||||
@@ -119,7 +93,9 @@ resource "aws_iam_role_policy_attachment" "controller_additional" {
|
||||
################################################################################
|
||||
|
||||
resource "aws_eks_pod_identity_association" "karpenter" {
|
||||
count = local.create_iam_role && var.enable_pod_identity && var.create_pod_identity_association ? 1 : 0
|
||||
count = local.create_iam_role && var.create_pod_identity_association ? 1 : 0
|
||||
|
||||
region = var.region
|
||||
|
||||
cluster_name = var.cluster_name
|
||||
namespace = var.namespace
|
||||
@@ -142,6 +118,8 @@ locals {
|
||||
resource "aws_sqs_queue" "this" {
|
||||
count = local.enable_spot_termination ? 1 : 0
|
||||
|
||||
region = var.region
|
||||
|
||||
name = local.queue_name
|
||||
message_retention_seconds = 300
|
||||
sqs_managed_sse_enabled = var.queue_managed_sse_enabled ? var.queue_managed_sse_enabled : null
|
||||
@@ -175,7 +153,7 @@ data "aws_iam_policy_document" "queue" {
|
||||
]
|
||||
resources = [aws_sqs_queue.this[0].arn]
|
||||
condition {
|
||||
test = "StringEquals"
|
||||
test = "Bool"
|
||||
variable = "aws:SecureTransport"
|
||||
values = [
|
||||
"false"
|
||||
@@ -193,6 +171,8 @@ data "aws_iam_policy_document" "queue" {
|
||||
resource "aws_sqs_queue_policy" "this" {
|
||||
count = local.enable_spot_termination ? 1 : 0
|
||||
|
||||
region = var.region
|
||||
|
||||
queue_url = aws_sqs_queue.this[0].url
|
||||
policy = data.aws_iam_policy_document.queue[0].json
|
||||
}
|
||||
@@ -241,6 +221,8 @@ locals {
|
||||
resource "aws_cloudwatch_event_rule" "this" {
|
||||
for_each = { for k, v in local.events : k => v if local.enable_spot_termination }
|
||||
|
||||
region = var.region
|
||||
|
||||
name_prefix = "${var.rule_name_prefix}${each.value.name}-"
|
||||
description = each.value.description
|
||||
event_pattern = jsonencode(each.value.event_pattern)
|
||||
@@ -254,6 +236,8 @@ resource "aws_cloudwatch_event_rule" "this" {
|
||||
resource "aws_cloudwatch_event_target" "this" {
|
||||
for_each = { for k, v in local.events : k => v if local.enable_spot_termination }
|
||||
|
||||
region = var.region
|
||||
|
||||
rule = aws_cloudwatch_event_rule.this[each.key].name
|
||||
target_id = "KarpenterInterruptionQueueTarget"
|
||||
arn = aws_sqs_queue.this[0].arn
|
||||
@@ -274,7 +258,7 @@ locals {
|
||||
AmazonEKS_CNI_Policy = "${local.node_iam_role_policy_prefix}/AmazonEKS_CNI_Policy"
|
||||
} : k => v if var.node_iam_role_attach_cni_policy && var.cluster_ip_family == "ipv4" }
|
||||
ipv6_cni_policy = { for k, v in {
|
||||
AmazonEKS_CNI_IPv6_Policy = "arn:${data.aws_partition.current.partition}:iam::${data.aws_caller_identity.current.account_id}:policy/AmazonEKS_CNI_IPv6_Policy"
|
||||
AmazonEKS_CNI_IPv6_Policy = "arn:${local.partition}:iam::${local.account_id}:policy/AmazonEKS_CNI_IPv6_Policy"
|
||||
} : k => v if var.node_iam_role_attach_cni_policy && var.cluster_ip_family == "ipv6" }
|
||||
}
|
||||
|
||||
@@ -337,6 +321,8 @@ resource "aws_iam_role_policy_attachment" "node_additional" {
|
||||
resource "aws_eks_access_entry" "node" {
|
||||
count = var.create && var.create_access_entry ? 1 : 0
|
||||
|
||||
region = var.region
|
||||
|
||||
cluster_name = var.cluster_name
|
||||
principal_arn = var.create_node_iam_role ? aws_iam_role.node[0].arn : var.node_iam_role_arn
|
||||
type = var.access_entry_type
|
||||
|
||||
+11
-364
@@ -1,357 +1,4 @@
|
||||
################################################################################
|
||||
# v0.33.x - v0.37.x Controller IAM Policy
|
||||
################################################################################
|
||||
|
||||
data "aws_iam_policy_document" "v033" {
|
||||
count = local.create_iam_role ? 1 : 0
|
||||
|
||||
statement {
|
||||
sid = "AllowScopedEC2InstanceActions"
|
||||
resources = [
|
||||
"arn:${local.partition}:ec2:*::image/*",
|
||||
"arn:${local.partition}:ec2:*::snapshot/*",
|
||||
"arn:${local.partition}:ec2:*:*:spot-instances-request/*",
|
||||
"arn:${local.partition}:ec2:*:*:security-group/*",
|
||||
"arn:${local.partition}:ec2:*:*:subnet/*",
|
||||
"arn:${local.partition}:ec2:*:*:launch-template/*",
|
||||
]
|
||||
|
||||
actions = [
|
||||
"ec2:RunInstances",
|
||||
"ec2:CreateFleet"
|
||||
]
|
||||
}
|
||||
|
||||
statement {
|
||||
sid = "AllowScopedEC2InstanceActionsWithTags"
|
||||
resources = [
|
||||
"arn:${local.partition}:ec2:*:*:fleet/*",
|
||||
"arn:${local.partition}:ec2:*:*:instance/*",
|
||||
"arn:${local.partition}:ec2:*:*:volume/*",
|
||||
"arn:${local.partition}:ec2:*:*:network-interface/*",
|
||||
"arn:${local.partition}:ec2:*:*:launch-template/*",
|
||||
"arn:${local.partition}:ec2:*:*:spot-instances-request/*",
|
||||
]
|
||||
actions = [
|
||||
"ec2:RunInstances",
|
||||
"ec2:CreateFleet",
|
||||
"ec2:CreateLaunchTemplate"
|
||||
]
|
||||
|
||||
condition {
|
||||
test = "StringEquals"
|
||||
variable = "aws:RequestTag/kubernetes.io/cluster/${var.cluster_name}"
|
||||
values = ["owned"]
|
||||
}
|
||||
|
||||
condition {
|
||||
test = "StringLike"
|
||||
variable = "aws:RequestTag/karpenter.sh/nodepool"
|
||||
values = ["*"]
|
||||
}
|
||||
}
|
||||
|
||||
statement {
|
||||
sid = "AllowScopedResourceCreationTagging"
|
||||
resources = [
|
||||
"arn:${local.partition}:ec2:*:*:fleet/*",
|
||||
"arn:${local.partition}:ec2:*:*:instance/*",
|
||||
"arn:${local.partition}:ec2:*:*:volume/*",
|
||||
"arn:${local.partition}:ec2:*:*:network-interface/*",
|
||||
"arn:${local.partition}:ec2:*:*:launch-template/*",
|
||||
"arn:${local.partition}:ec2:*:*:spot-instances-request/*",
|
||||
]
|
||||
actions = ["ec2:CreateTags"]
|
||||
|
||||
condition {
|
||||
test = "StringEquals"
|
||||
variable = "aws:RequestTag/kubernetes.io/cluster/${var.cluster_name}"
|
||||
values = ["owned"]
|
||||
}
|
||||
|
||||
condition {
|
||||
test = "StringEquals"
|
||||
variable = "ec2:CreateAction"
|
||||
values = [
|
||||
"RunInstances",
|
||||
"CreateFleet",
|
||||
"CreateLaunchTemplate",
|
||||
]
|
||||
}
|
||||
|
||||
condition {
|
||||
test = "StringLike"
|
||||
variable = "aws:RequestTag/karpenter.sh/nodepool"
|
||||
values = ["*"]
|
||||
}
|
||||
}
|
||||
|
||||
statement {
|
||||
sid = "AllowScopedResourceTagging"
|
||||
resources = ["arn:${local.partition}:ec2:*:*:instance/*"]
|
||||
actions = ["ec2:CreateTags"]
|
||||
|
||||
condition {
|
||||
test = "StringEquals"
|
||||
variable = "aws:ResourceTag/kubernetes.io/cluster/${var.cluster_name}"
|
||||
values = ["owned"]
|
||||
}
|
||||
|
||||
condition {
|
||||
test = "StringLike"
|
||||
variable = "aws:ResourceTag/karpenter.sh/nodepool"
|
||||
values = ["*"]
|
||||
}
|
||||
|
||||
condition {
|
||||
test = "ForAllValues:StringEquals"
|
||||
variable = "aws:TagKeys"
|
||||
values = [
|
||||
"karpenter.sh/nodeclaim",
|
||||
"Name",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
statement {
|
||||
sid = "AllowScopedDeletion"
|
||||
resources = [
|
||||
"arn:${local.partition}:ec2:*:*:instance/*",
|
||||
"arn:${local.partition}:ec2:*:*:launch-template/*"
|
||||
]
|
||||
|
||||
actions = [
|
||||
"ec2:TerminateInstances",
|
||||
"ec2:DeleteLaunchTemplate"
|
||||
]
|
||||
|
||||
condition {
|
||||
test = "StringEquals"
|
||||
variable = "aws:ResourceTag/kubernetes.io/cluster/${var.cluster_name}"
|
||||
values = ["owned"]
|
||||
}
|
||||
|
||||
condition {
|
||||
test = "StringLike"
|
||||
variable = "aws:ResourceTag/karpenter.sh/nodepool"
|
||||
values = ["*"]
|
||||
}
|
||||
}
|
||||
|
||||
statement {
|
||||
sid = "AllowRegionalReadActions"
|
||||
resources = ["*"]
|
||||
actions = [
|
||||
"ec2:DescribeAvailabilityZones",
|
||||
"ec2:DescribeImages",
|
||||
"ec2:DescribeInstances",
|
||||
"ec2:DescribeInstanceTypeOfferings",
|
||||
"ec2:DescribeInstanceTypes",
|
||||
"ec2:DescribeLaunchTemplates",
|
||||
"ec2:DescribeSecurityGroups",
|
||||
"ec2:DescribeSpotPriceHistory",
|
||||
"ec2:DescribeSubnets"
|
||||
]
|
||||
|
||||
condition {
|
||||
test = "StringEquals"
|
||||
variable = "aws:RequestedRegion"
|
||||
values = [local.region]
|
||||
}
|
||||
}
|
||||
|
||||
statement {
|
||||
sid = "AllowSSMReadActions"
|
||||
resources = coalescelist(var.ami_id_ssm_parameter_arns, ["arn:${local.partition}:ssm:${local.region}::parameter/aws/service/*"])
|
||||
actions = ["ssm:GetParameter"]
|
||||
}
|
||||
|
||||
statement {
|
||||
sid = "AllowPricingReadActions"
|
||||
resources = ["*"]
|
||||
actions = ["pricing:GetProducts"]
|
||||
}
|
||||
|
||||
dynamic "statement" {
|
||||
for_each = local.enable_spot_termination ? [1] : []
|
||||
|
||||
content {
|
||||
sid = "AllowInterruptionQueueActions"
|
||||
resources = [try(aws_sqs_queue.this[0].arn, null)]
|
||||
actions = [
|
||||
"sqs:DeleteMessage",
|
||||
"sqs:GetQueueAttributes",
|
||||
"sqs:GetQueueUrl",
|
||||
"sqs:ReceiveMessage"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
statement {
|
||||
sid = "AllowPassingInstanceRole"
|
||||
resources = var.create_node_iam_role ? [aws_iam_role.node[0].arn] : [var.node_iam_role_arn]
|
||||
actions = ["iam:PassRole"]
|
||||
|
||||
condition {
|
||||
test = "StringEquals"
|
||||
variable = "iam:PassedToService"
|
||||
values = ["ec2.${local.dns_suffix}"]
|
||||
}
|
||||
}
|
||||
|
||||
statement {
|
||||
sid = "AllowScopedInstanceProfileCreationActions"
|
||||
resources = ["*"]
|
||||
actions = ["iam:CreateInstanceProfile"]
|
||||
|
||||
condition {
|
||||
test = "StringEquals"
|
||||
variable = "aws:RequestTag/kubernetes.io/cluster/${var.cluster_name}"
|
||||
values = ["owned"]
|
||||
}
|
||||
|
||||
condition {
|
||||
test = "StringEquals"
|
||||
variable = "aws:RequestTag/topology.kubernetes.io/region"
|
||||
values = [local.region]
|
||||
}
|
||||
|
||||
condition {
|
||||
test = "StringLike"
|
||||
variable = "aws:RequestTag/karpenter.k8s.aws/ec2nodeclass"
|
||||
values = ["*"]
|
||||
}
|
||||
}
|
||||
|
||||
statement {
|
||||
sid = "AllowScopedInstanceProfileTagActions"
|
||||
resources = ["*"]
|
||||
actions = ["iam:TagInstanceProfile"]
|
||||
|
||||
condition {
|
||||
test = "StringEquals"
|
||||
variable = "aws:ResourceTag/kubernetes.io/cluster/${var.cluster_name}"
|
||||
values = ["owned"]
|
||||
}
|
||||
|
||||
condition {
|
||||
test = "StringEquals"
|
||||
variable = "aws:ResourceTag/topology.kubernetes.io/region"
|
||||
values = [local.region]
|
||||
}
|
||||
|
||||
condition {
|
||||
test = "StringEquals"
|
||||
variable = "aws:RequestTag/kubernetes.io/cluster/${var.cluster_name}"
|
||||
values = ["owned"]
|
||||
}
|
||||
|
||||
condition {
|
||||
test = "StringEquals"
|
||||
variable = "aws:ResourceTag/topology.kubernetes.io/region"
|
||||
values = [local.region]
|
||||
}
|
||||
|
||||
condition {
|
||||
test = "StringLike"
|
||||
variable = "aws:ResourceTag/karpenter.k8s.aws/ec2nodeclass"
|
||||
values = ["*"]
|
||||
}
|
||||
|
||||
condition {
|
||||
test = "StringLike"
|
||||
variable = "aws:RequestTag/karpenter.k8s.aws/ec2nodeclass"
|
||||
values = ["*"]
|
||||
}
|
||||
}
|
||||
|
||||
statement {
|
||||
sid = "AllowScopedInstanceProfileActions"
|
||||
resources = ["*"]
|
||||
actions = [
|
||||
"iam:AddRoleToInstanceProfile",
|
||||
"iam:RemoveRoleFromInstanceProfile",
|
||||
"iam:DeleteInstanceProfile"
|
||||
]
|
||||
|
||||
condition {
|
||||
test = "StringEquals"
|
||||
variable = "aws:ResourceTag/kubernetes.io/cluster/${var.cluster_name}"
|
||||
values = ["owned"]
|
||||
}
|
||||
|
||||
condition {
|
||||
test = "StringEquals"
|
||||
variable = "aws:ResourceTag/topology.kubernetes.io/region"
|
||||
values = [local.region]
|
||||
}
|
||||
|
||||
condition {
|
||||
test = "StringLike"
|
||||
variable = "aws:ResourceTag/karpenter.k8s.aws/ec2nodeclass"
|
||||
values = ["*"]
|
||||
}
|
||||
}
|
||||
|
||||
statement {
|
||||
sid = "AllowInstanceProfileReadActions"
|
||||
resources = ["*"]
|
||||
actions = ["iam:GetInstanceProfile"]
|
||||
}
|
||||
|
||||
statement {
|
||||
sid = "AllowAPIServerEndpointDiscovery"
|
||||
resources = ["arn:${local.partition}:eks:${local.region}:${local.account_id}:cluster/${var.cluster_name}"]
|
||||
actions = ["eks:DescribeCluster"]
|
||||
}
|
||||
|
||||
dynamic "statement" {
|
||||
for_each = var.iam_policy_statements
|
||||
|
||||
content {
|
||||
sid = try(statement.value.sid, null)
|
||||
actions = try(statement.value.actions, null)
|
||||
not_actions = try(statement.value.not_actions, null)
|
||||
effect = try(statement.value.effect, null)
|
||||
resources = try(statement.value.resources, null)
|
||||
not_resources = try(statement.value.not_resources, null)
|
||||
|
||||
dynamic "principals" {
|
||||
for_each = try(statement.value.principals, [])
|
||||
|
||||
content {
|
||||
type = principals.value.type
|
||||
identifiers = principals.value.identifiers
|
||||
}
|
||||
}
|
||||
|
||||
dynamic "not_principals" {
|
||||
for_each = try(statement.value.not_principals, [])
|
||||
|
||||
content {
|
||||
type = not_principals.value.type
|
||||
identifiers = not_principals.value.identifiers
|
||||
}
|
||||
}
|
||||
|
||||
dynamic "condition" {
|
||||
for_each = try(statement.value.conditions, [])
|
||||
|
||||
content {
|
||||
test = condition.value.test
|
||||
values = condition.value.values
|
||||
variable = condition.value.variable
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# v1.0.x Controller IAM Policy
|
||||
################################################################################
|
||||
|
||||
data "aws_iam_policy_document" "v1" {
|
||||
data "aws_iam_policy_document" "controller" {
|
||||
count = local.create_iam_role ? 1 : 0
|
||||
|
||||
statement {
|
||||
@@ -708,18 +355,18 @@ data "aws_iam_policy_document" "v1" {
|
||||
}
|
||||
|
||||
dynamic "statement" {
|
||||
for_each = var.iam_policy_statements
|
||||
for_each = var.iam_policy_statements != null ? var.iam_policy_statements : []
|
||||
|
||||
content {
|
||||
sid = try(statement.value.sid, null)
|
||||
actions = try(statement.value.actions, null)
|
||||
not_actions = try(statement.value.not_actions, null)
|
||||
effect = try(statement.value.effect, null)
|
||||
resources = try(statement.value.resources, null)
|
||||
not_resources = try(statement.value.not_resources, null)
|
||||
sid = statement.value.sid
|
||||
actions = statement.value.actions
|
||||
not_actions = statement.value.not_actions
|
||||
effect = statement.value.effect
|
||||
resources = statement.value.resources
|
||||
not_resources = statement.value.not_resources
|
||||
|
||||
dynamic "principals" {
|
||||
for_each = try(statement.value.principals, [])
|
||||
for_each = statement.value.principals != null ? statement.value.principals : []
|
||||
|
||||
content {
|
||||
type = principals.value.type
|
||||
@@ -728,7 +375,7 @@ data "aws_iam_policy_document" "v1" {
|
||||
}
|
||||
|
||||
dynamic "not_principals" {
|
||||
for_each = try(statement.value.not_principals, [])
|
||||
for_each = statement.value.not_principals != null ? statement.value.not_principals : []
|
||||
|
||||
content {
|
||||
type = not_principals.value.type
|
||||
@@ -737,7 +384,7 @@ data "aws_iam_policy_document" "v1" {
|
||||
}
|
||||
|
||||
dynamic "condition" {
|
||||
for_each = try(statement.value.conditions, [])
|
||||
for_each = statement.value.condition != null ? statement.value.condition : []
|
||||
|
||||
content {
|
||||
test = condition.value.test
|
||||
|
||||
@@ -16,6 +16,12 @@ variable "cluster_name" {
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "region" {
|
||||
description = "Region where the resource(s) will be managed. Defaults to the Region set in the provider configuration"
|
||||
type = string
|
||||
default = null
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Karpenter controller IAM Role
|
||||
################################################################################
|
||||
@@ -64,7 +70,7 @@ variable "iam_role_permissions_boundary_arn" {
|
||||
|
||||
variable "iam_role_tags" {
|
||||
description = "A map of additional tags to add the the IAM role"
|
||||
type = map(any)
|
||||
type = map(string)
|
||||
default = {}
|
||||
}
|
||||
|
||||
@@ -92,10 +98,42 @@ variable "iam_policy_description" {
|
||||
default = "Karpenter controller IAM policy"
|
||||
}
|
||||
|
||||
variable "iam_role_override_assume_policy_documents" {
|
||||
description = "A list of IAM policy documents to override the default assume role policy document for the Karpenter controller IAM role"
|
||||
type = list(string)
|
||||
default = []
|
||||
}
|
||||
|
||||
variable "iam_role_source_assume_policy_documents" {
|
||||
description = "A list of IAM policy documents to use as a source for the assume role policy document for the Karpenter controller IAM role"
|
||||
type = list(string)
|
||||
default = []
|
||||
}
|
||||
|
||||
variable "iam_policy_statements" {
|
||||
description = "A list of IAM policy [statements](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document#statement) - used for adding specific IAM permissions as needed"
|
||||
type = any
|
||||
default = []
|
||||
type = list(object({
|
||||
sid = optional(string)
|
||||
actions = optional(list(string))
|
||||
not_actions = optional(list(string))
|
||||
effect = optional(string)
|
||||
resources = optional(list(string))
|
||||
not_resources = optional(list(string))
|
||||
principals = optional(list(object({
|
||||
type = string
|
||||
identifiers = list(string)
|
||||
})))
|
||||
not_principals = optional(list(object({
|
||||
type = string
|
||||
identifiers = list(string)
|
||||
})))
|
||||
condition = optional(list(object({
|
||||
test = string
|
||||
values = list(string)
|
||||
variable = string
|
||||
})))
|
||||
}))
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "iam_role_policies" {
|
||||
@@ -110,55 +148,14 @@ variable "ami_id_ssm_parameter_arns" {
|
||||
default = []
|
||||
}
|
||||
|
||||
variable "enable_pod_identity" {
|
||||
description = "Determines whether to enable support for EKS pod identity"
|
||||
type = bool
|
||||
default = true
|
||||
}
|
||||
|
||||
# TODO - make v1 permssions the default policy at next breaking change
|
||||
variable "enable_v1_permissions" {
|
||||
description = "Determines whether to enable permissions suitable for v1+ (`true`) or for v0.33.x-v0.37.x (`false`)"
|
||||
type = bool
|
||||
default = false
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# IAM Role for Service Account (IRSA)
|
||||
################################################################################
|
||||
|
||||
variable "enable_irsa" {
|
||||
description = "Determines whether to enable support for IAM role for service accounts"
|
||||
type = bool
|
||||
default = false
|
||||
}
|
||||
|
||||
variable "irsa_oidc_provider_arn" {
|
||||
description = "OIDC provider arn used in trust policy for IAM role for service accounts"
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "irsa_namespace_service_accounts" {
|
||||
description = "List of `namespace:serviceaccount`pairs to use in trust policy for IAM role for service accounts"
|
||||
type = list(string)
|
||||
default = ["karpenter:karpenter"]
|
||||
}
|
||||
|
||||
variable "irsa_assume_role_condition_test" {
|
||||
description = "Name of the [IAM condition operator](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition_operators.html) to evaluate when assuming the role"
|
||||
type = string
|
||||
default = "StringEquals"
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Pod Identity Association
|
||||
################################################################################
|
||||
# TODO - Change default to `true` at next breaking change
|
||||
|
||||
variable "create_pod_identity_association" {
|
||||
description = "Determines whether to create pod identity association"
|
||||
type = bool
|
||||
default = false
|
||||
default = true
|
||||
}
|
||||
|
||||
variable "namespace" {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
terraform {
|
||||
required_version = ">= 1.3.2"
|
||||
required_version = ">= 1.5.7"
|
||||
|
||||
required_providers {
|
||||
aws = {
|
||||
source = "hashicorp/aws"
|
||||
version = ">= 5.95, < 6.0.0"
|
||||
version = ">= 6.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user