diff --git a/modules/iam-role-for-service-accounts-eks/README.md b/modules/iam-role-for-service-accounts-eks/README.md index ceafe97c..fba28cfa 100644 --- a/modules/iam-role-for-service-accounts-eks/README.md +++ b/modules/iam-role-for-service-accounts-eks/README.md @@ -206,6 +206,7 @@ No modules. | [karpenter\_controller\_cluster\_id](#input\_karpenter\_controller\_cluster\_id) | Cluster ID where the Karpenter controller is provisioned/managing | `string` | `"*"` | no | | [karpenter\_controller\_node\_iam\_role\_arns](#input\_karpenter\_controller\_node\_iam\_role\_arns) | List of node IAM role ARNs Karpenter can use to launch nodes | `list(string)` |
[
"*"
]
| no | | [karpenter\_controller\_ssm\_parameter\_arns](#input\_karpenter\_controller\_ssm\_parameter\_arns) | List of SSM Parameter ARNs that contain AMI IDs launched by Karpenter | `list(string)` |
[
"arn:aws:ssm:*:*:parameter/aws/service/*"
]
| no | +| [karpenter\_sqs\_queue\_arn](#input\_karpenter\_sqs\_queue\_arn) | (Optional) ARN of SQS used by Karpenter when native node termination handling is enabled | `string` | `null` | no | | [karpenter\_subnet\_account\_id](#input\_karpenter\_subnet\_account\_id) | Account ID of where the subnets Karpenter will utilize resides. Used when subnets are shared from another account | `string` | `""` | no | | [karpenter\_tag\_key](#input\_karpenter\_tag\_key) | Tag key (`{key = value}`) applied to resources launched by Karpenter through the Karpenter provisioner | `string` | `"karpenter.sh/discovery"` | no | | [max\_session\_duration](#input\_max\_session\_duration) | Maximum CLI/API session duration in seconds between 3600 and 43200 | `number` | `null` | no | diff --git a/modules/iam-role-for-service-accounts-eks/policies.tf b/modules/iam-role-for-service-accounts-eks/policies.tf index b809b10e..d4ff8289 100644 --- a/modules/iam-role-for-service-accounts-eks/policies.tf +++ b/modules/iam-role-for-service-accounts-eks/policies.tf @@ -509,24 +509,25 @@ resource "aws_iam_role_policy_attachment" "fsx_lustre_csi" { # Karpenter Controller Policy ################################################################################ -# curl -fsSL https://karpenter.sh/v0.6.1/getting-started/cloudformation.yaml +# https://github.com/aws/karpenter/blob/502d275cc330fb0f2435b124935c49632146d945/website/content/en/v0.19.0/getting-started/getting-started-with-eksctl/cloudformation.yaml#L34 data "aws_iam_policy_document" "karpenter_controller" { count = var.create_role && var.attach_karpenter_controller_policy ? 1 : 0 statement { actions = [ - "ec2:CreateLaunchTemplate", "ec2:CreateFleet", + "ec2:CreateLaunchTemplate", "ec2:CreateTags", - "ec2:DescribeLaunchTemplates", + "ec2:DescribeAvailabilityZones", + "ec2:DescribeImages", "ec2:DescribeImages", "ec2:DescribeInstances", - "ec2:DescribeSecurityGroups", - "ec2:DescribeSubnets", - "ec2:DescribeInstanceTypes", "ec2:DescribeInstanceTypeOfferings", - "ec2:DescribeAvailabilityZones", + "ec2:DescribeInstanceTypes", + "ec2:DescribeLaunchTemplates", + "ec2:DescribeSecurityGroups", "ec2:DescribeSpotPriceHistory", + "ec2:DescribeSubnets", "pricing:GetProducts", ] @@ -583,6 +584,20 @@ data "aws_iam_policy_document" "karpenter_controller" { actions = ["iam:PassRole"] resources = var.karpenter_controller_node_iam_role_arns } + + dynamic "statement" { + for_each = var.karpenter_sqs_queue_arn != null ? [1] : [] + + content { + actions = [ + "sqs:DeleteMessage", + "sqs:GetQueueAttributes", + "sqs:GetQueueUrl", + "sqs:ReceiveMessage", + ] + resources = [var.karpenter_sqs_queue_arn] + } + } } resource "aws_iam_policy" "karpenter_controller" { diff --git a/modules/iam-role-for-service-accounts-eks/variables.tf b/modules/iam-role-for-service-accounts-eks/variables.tf index c9192edb..1eae9778 100644 --- a/modules/iam-role-for-service-accounts-eks/variables.tf +++ b/modules/iam-role-for-service-accounts-eks/variables.tf @@ -215,6 +215,12 @@ variable "karpenter_subnet_account_id" { default = "" } +variable "karpenter_sqs_queue_arn" { + description = "(Optional) ARN of SQS used by Karpenter when native node termination handling is enabled" + type = string + default = null +} + # AWS Load Balancer Controller variable "attach_load_balancer_controller_policy" { description = "Determines whether to attach the Load Balancer Controller policy to the role"