Skip to content

Commit bc7acc0

Browse files
committed
add cluster_name var
1 parent 227661b commit bc7acc0

14 files changed

Lines changed: 72 additions & 17 deletions

File tree

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ The module expects you to provide existing subnet IDs. In most deployments these
1616
module "eks" {
1717
source = "./eks"
1818
19-
name = "dev-eks"
20-
subnet_ids = ["subnet-0123456789abcdef0", "subnet-0fedcba9876543210"]
19+
name = "dev"
20+
cluster_name = "dev-eks"
21+
subnet_ids = ["subnet-0123456789abcdef0", "subnet-0fedcba9876543210"]
2122
2223
node_groups = {
2324
default = {
@@ -81,11 +82,12 @@ aws eks update-kubeconfig --name dev-eks
8182
| ---- | ----------- | ---- | ------- | :------: |
8283
| <a name="input_addons"></a> [addons](#input\_addons) | EKS add-ons to install after the managed node groups are created. | <pre>map(object({<br/> configuration_values = optional(string)<br/> resolve_conflicts_on_create = optional(string, "OVERWRITE")<br/> resolve_conflicts_on_update = optional(string, "OVERWRITE")<br/> service_account_role_arn = optional(string)<br/> version = optional(string)<br/> }))</pre> | <pre>{<br/> "coredns": {},<br/> "kube-proxy": {},<br/> "vpc-cni": {}<br/>}</pre> | no |
8384
| <a name="input_cloudwatch_log_retention_days"></a> [cloudwatch\_log\_retention\_days](#input\_cloudwatch\_log\_retention\_days) | Retention in days for the EKS control plane CloudWatch log group. | `number` | `30` | no |
85+
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | Optional EKS cluster name. When null, name is used as the cluster name. | `string` | `null` | no |
8486
| <a name="input_enabled_cluster_log_types"></a> [enabled\_cluster\_log\_types](#input\_enabled\_cluster\_log\_types) | EKS control plane log types to enable. | `list(string)` | <pre>[<br/> "api",<br/> "audit",<br/> "authenticator"<br/>]</pre> | no |
8587
| <a name="input_endpoint_private_access"></a> [endpoint\_private\_access](#input\_endpoint\_private\_access) | Whether the Kubernetes API server endpoint is reachable from within the VPC. | `bool` | `true` | no |
8688
| <a name="input_endpoint_public_access"></a> [endpoint\_public\_access](#input\_endpoint\_public\_access) | Whether the Kubernetes API server endpoint is reachable from the public internet. | `bool` | `true` | no |
8789
| <a name="input_kubernetes_version"></a> [kubernetes\_version](#input\_kubernetes\_version) | Kubernetes version for the EKS cluster and managed node groups. Leave null to use the current AWS default. | `string` | `null` | no |
88-
| <a name="input_name"></a> [name](#input\_name) | Name of the EKS cluster. | `string` | n/a | yes |
90+
| <a name="input_name"></a> [name](#input\_name) | Name prefix for module-created resources. Used as the EKS cluster name when cluster\_name is null. | `string` | n/a | yes |
8991
| <a name="input_node_groups"></a> [node\_groups](#input\_node\_groups) | Managed node groups to create. | <pre>map(object({<br/> ami_type = optional(string)<br/> capacity_type = optional(string, "ON_DEMAND")<br/> desired_size = optional(number, 2)<br/> disk_size = optional(number, 20)<br/> instance_types = optional(list(string), ["t3.medium"])<br/> labels = optional(map(string), {})<br/> max_size = optional(number, 3)<br/> min_size = optional(number, 1)<br/> subnet_ids = optional(list(string), [])<br/> update_max_unavailable = optional(number, 1)<br/> taints = optional(list(object({<br/> effect = string<br/> key = string<br/> value = optional(string, "")<br/> })), [])<br/> }))</pre> | <pre>{<br/> "default": {}<br/>}</pre> | no |
9092
| <a name="input_public_access_cidrs"></a> [public\_access\_cidrs](#input\_public\_access\_cidrs) | CIDR blocks that can access the public Kubernetes API endpoint. | `list(string)` | <pre>[<br/> "0.0.0.0/0"<br/>]</pre> | no |
9193
| <a name="input_service_ipv4_cidr"></a> [service\_ipv4\_cidr](#input\_service\_ipv4\_cidr) | Optional Kubernetes service IPv4 CIDR. Set only when you need a non-default service CIDR. | `string` | `null` | no |

examples/advanced/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This example shows:
88
- Full control-plane logging with configurable retention.
99
- Separate on-demand and spot managed node groups.
1010
- Optional node-group subnet overrides.
11+
- Separate module resource prefix and EKS cluster name through `name` and `cluster_name`.
1112
- VPC CNI prefix delegation configuration.
1213
- Additional EKS add-ons for identity, storage snapshots, node health, metrics, certificates, Prometheus exporters, and log forwarding.
1314
- Optional IAM-backed add-ons for EBS CSI, EFS CSI, CloudWatch Observability, and ExternalDNS when their service-account role ARNs are supplied.

examples/advanced/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module "eks" {
1717
source = "../.."
1818

1919
name = var.name
20+
cluster_name = var.cluster_name
2021
kubernetes_version = var.kubernetes_version
2122
subnet_ids = var.control_plane_subnet_ids
2223

examples/advanced/variables.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@ variable "region" {
55
}
66

77
variable "name" {
8-
description = "Name of the EKS cluster."
8+
description = "Name prefix for module-created resources."
99
type = string
10-
default = "advanced-eks"
10+
default = "advanced"
11+
}
12+
13+
variable "cluster_name" {
14+
description = "Optional EKS cluster name. When null, name is used as the cluster name."
15+
type = string
16+
default = null
1117
}
1218

1319
variable "kubernetes_version" {

examples/basic/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module "eks" {
1717
source = "../.."
1818

1919
name = var.name
20+
cluster_name = var.cluster_name
2021
kubernetes_version = var.kubernetes_version
2122
subnet_ids = var.subnet_ids
2223

examples/basic/variables.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@ variable "region" {
55
}
66

77
variable "name" {
8-
description = "Name of the EKS cluster."
8+
description = "Name prefix for module-created resources."
99
type = string
10-
default = "example-eks"
10+
default = "example"
11+
}
12+
13+
variable "cluster_name" {
14+
description = "Optional EKS cluster name. When null, name is used as the cluster name."
15+
type = string
16+
default = null
1117
}
1218

1319
variable "kubernetes_version" {

examples/minimal/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ Provide existing subnet IDs before planning or applying:
1313
terraform init
1414
terraform plan -var='subnet_ids=["subnet-0123456789abcdef0","subnet-0fedcba9876543210"]'
1515
```
16+
17+
Set `cluster_name` when the EKS cluster name should differ from the module resource prefix in `name`.

examples/minimal/main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ provider "aws" {
1616
module "eks" {
1717
source = "../.."
1818

19-
name = var.name
20-
subnet_ids = var.subnet_ids
19+
name = var.name
20+
cluster_name = var.cluster_name
21+
subnet_ids = var.subnet_ids
2122

2223
tags = var.tags
2324
}

examples/minimal/variables.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@ variable "region" {
55
}
66

77
variable "name" {
8-
description = "Name of the EKS cluster."
8+
description = "Name prefix for module-created resources."
99
type = string
10-
default = "minimal-eks"
10+
default = "minimal"
11+
}
12+
13+
variable "cluster_name" {
14+
description = "Optional EKS cluster name. When null, name is used as the cluster name."
15+
type = string
16+
default = null
1117
}
1218

1319
variable "subnet_ids" {

locals.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
locals {
2+
cluster_name = coalesce(var.cluster_name, var.name)
3+
24
common_tags = merge(
35
var.tags,
46
{
57
"terraform-module" = "eks"
6-
"eks-cluster" = var.name
8+
"eks-cluster" = local.cluster_name
79
}
810
)
911

0 commit comments

Comments
 (0)