Skip to content

Commit

Permalink
add ami-type var and set to AL2023 (#29)
Browse files Browse the repository at this point in the history
* add ami-type var and set to AL2023

* fix var

* enable inline policy to avoid policy size limits

* removed default true options
  • Loading branch information
morga471 committed Jul 24, 2026
1 parent 34f469f commit 4a5b8c7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ The module deploys Karpenter needed AWS resources, namely in IAM. It copies the
| Name | Source | Version |
|------|--------|---------|
| <a name="module_images"></a> [images](#module\_images) | git::https://github.e.it.census.gov/terraform-modules/aws-ecr-copy-images.git | tf-upgrade |
| <a name="module_karpenter_resources"></a> [karpenter\_resources](#module\_karpenter\_resources) | git::https://github.e.it.census.gov/SCT-Engineering/terraform-aws-eks.git//modules/karpenter | v21.15.1 |
| <a name="module_karpenter_resources"></a> [karpenter\_resources](#module\_karpenter\_resources) | git::https://github.e.it.census.gov/SCT-Engineering/terraform-aws-eks.git//modules/karpenter | v21.23.0 |

## Resources

Expand All @@ -57,6 +57,7 @@ The module deploys Karpenter needed AWS resources, namely in IAM. It copies the
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_account_id"></a> [account\_id](#input\_account\_id) | aws account number | `string` | `""` | no |
| <a name="input_ami_type"></a> [ami\_type](#input\_ami\_type) | AMI type to use for the Karpenter node group | `string` | `"AL2023_x86_64_STANDARD"` | no |
| <a name="input_cluster_endpoint"></a> [cluster\_endpoint](#input\_cluster\_endpoint) | Endpoint for your Kubernetes API server | `string` | n/a | yes |
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | EKS cluster name name component used through out the EKS cluster describing its purpose (ex: dice-dev) | `string` | n/a | yes |
| <a name="input_create_spot_service_linked_role"></a> [create\_spot\_service\_linked\_role](#input\_create\_spot\_service\_linked\_role) | Whether to create the service-linked role for EC2 Spot (required for Karpenter spot instances) | `bool` | `false` | no |
Expand Down
28 changes: 12 additions & 16 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
locals {
amd_ami_family = "Bottlerocket"
amd_ami_alias = "bottlerocket@latest"
ami_type_family = upper(split("_", var.ami_type)[0])
amd_ami_family = local.ami_type_family
amd_ami_alias = lower(format("%v@latest", local.amd_ami_family))

# Calculate the role name with prefix
role_name_raw = format("%v%v-%v", local.prefixes["eks-role"], var.cluster_name, "karpenter")
Expand All @@ -17,23 +18,20 @@ locals {
rule_name_prefix = length(local.rule_name_raw) > local.max_rule_name_length ? substr(local.rule_name_raw, 0, local.max_rule_name_length) : local.rule_name_raw
queue_name = format("%v%v", local.prefixes["eks-queue"], var.cluster_name)
subnet_ids = try(tolist(var.subnets), [])

}

# Replicating from here: https://github.e.it.census.gov/SCT-Engineering/terraform-aws-eks/tree/master/modules/karpenter
# Karpenter IRSA roles and policies
module "karpenter_resources" {
source = "git::https://github.e.it.census.gov/SCT-Engineering/terraform-aws-eks.git//modules/karpenter?ref=v21.15.1"

cluster_name = var.cluster_name
create_access_entry = true
create_instance_profile = true
create_node_iam_role = true
create_pod_identity_association = true
namespace = var.namespace
node_iam_role_name = local.node_iam_role_name
queue_name = local.queue_name
rule_name_prefix = local.rule_name_prefix
source = "git::https://github.e.it.census.gov/SCT-Engineering/terraform-aws-eks.git//modules/karpenter?ref=v21.23.0"

cluster_name = var.cluster_name
enable_inline_policy = true
create_instance_profile = true
namespace = var.namespace
node_iam_role_name = local.node_iam_role_name
queue_name = local.queue_name
rule_name_prefix = local.rule_name_prefix
# Attach additional IAM policies to the Karpenter node IAM role
node_iam_role_additional_policies = {
AmazonSSMManagedInstanceCore = format("arn:%v:iam::%v:%v", data.aws_arn.current.partition, "aws", "policy/AmazonSSMManagedInstanceCore")
Expand All @@ -42,8 +40,6 @@ module "karpenter_resources" {
CloudWatchAgentServerPolicy = format("arn:%v:iam::aws:%v", data.aws_arn.current.partition, "policy/CloudWatchAgentServerPolicy")

}

tags = var.tags
}

# Install Karpenter
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,9 @@ variable "create_spot_service_linked_role" {
type = bool
default = false
}

variable "ami_type" {
description = "AMI type to use for the Karpenter node group"
type = string
default = "AL2023_x86_64_STANDARD"
}

0 comments on commit 4a5b8c7

Please sign in to comment.