Skip to content

Commit 61b6d15

Browse files
committed
feat(eks-cluster): support aws v6
1 parent ba64fac commit 61b6d15

File tree

12 files changed

+420
-88
lines changed

12 files changed

+420
-88
lines changed

modules/eks-cluster/README.md

Lines changed: 31 additions & 19 deletions
Large diffs are not rendered by default.

modules/eks-cluster/cloudwatch.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
data "aws_cloudwatch_log_group" "this" {
2+
count = var.logging.enabled ? 1 : 0
3+
4+
region = var.region
5+
26
name = "/aws/eks/${aws_eks_cluster.this.name}/cluster"
37
}

modules/eks-cluster/iam.tf

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module "role" {
66
count = var.default_cluster_role.enabled ? 1 : 0
77

88
source = "tedilabs/account/aws//modules/iam-role"
9-
version = "~> 0.30.0"
9+
version = "~> 0.33.0"
1010

1111
name = coalesce(
1212
var.default_cluster_role.name,
@@ -27,9 +27,11 @@ module "role" {
2727
)
2828
inline_policies = var.default_cluster_role.inline_policies
2929

30-
force_detach_policies = true
31-
resource_group_enabled = false
32-
module_tags_enabled = false
30+
force_detach_policies = true
31+
resource_group = {
32+
enabled = false
33+
}
34+
module_tags_enabled = false
3335

3436
tags = merge(
3537
local.module_tags,
@@ -46,7 +48,7 @@ module "role__node" {
4648
count = var.default_node_role.enabled ? 1 : 0
4749

4850
source = "tedilabs/account/aws//modules/iam-role"
49-
version = "~> 0.30.0"
51+
version = "~> 0.33.0"
5052

5153
name = coalesce(
5254
var.default_node_role.name,
@@ -74,9 +76,11 @@ module "role__node" {
7476
enabled = true
7577
}
7678

77-
force_detach_policies = true
78-
resource_group_enabled = false
79-
module_tags_enabled = false
79+
force_detach_policies = true
80+
resource_group = {
81+
enabled = false
82+
}
83+
module_tags_enabled = false
8084

8185
tags = merge(
8286
local.module_tags,

modules/eks-cluster/irsa-oidc-provider.tf

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@
44

55
module "oidc_provider" {
66
source = "tedilabs/account/aws//modules/iam-oidc-identity-provider"
7-
version = "~> 0.30.0"
7+
version = "~> 0.33.0"
8+
9+
count = var.irsa_oidc_provider.enabled ? 1 : 0
810

911
url = aws_eks_cluster.this.identity[0].oidc[0].issuer
1012
audiences = ["sts.amazonaws.com"]
1113

1214
auto_thumbprint_enabled = true
1315

14-
resource_group_enabled = false
15-
module_tags_enabled = false
16+
resource_group = {
17+
enabled = false
18+
}
19+
module_tags_enabled = false
1620

1721
tags = merge(
1822
local.module_tags,

modules/eks-cluster/main.tf

Lines changed: 89 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,35 @@ locals {
2626
# EKS Control Plane
2727
###################################################
2828

29+
# INFO: EKS Auto-mode Only
30+
# - `compute_config`
31+
# - `kubernetes_network_config[].elastic_load_balancing.enabled`
32+
# - `storage_config`
2933
resource "aws_eks_cluster" "this" {
30-
name = var.name
31-
version = var.kubernetes_version
34+
region = var.region
35+
36+
name = var.name
37+
deletion_protection = var.deletion_protection_enabled
38+
bootstrap_self_managed_addons = var.bootstrap_self_managed_addons
39+
3240
role_arn = (var.default_cluster_role.enabled
3341
? module.role[0].arn
3442
: var.cluster_role
3543
)
3644

37-
enabled_cluster_log_types = var.log_types
45+
enabled_cluster_log_types = var.logging.enabled ? var.logging.log_types : []
46+
47+
zonal_shift_config {
48+
enabled = var.arc_zonal_shift.enabled
49+
}
50+
51+
## Versioning
52+
version = var.kubernetes_version
53+
force_update_version = var.upgrade_policy.force_upgrade
54+
55+
upgrade_policy {
56+
support_type = var.upgrade_policy.support_type
57+
}
3858

3959

4060
## Network
@@ -56,10 +76,10 @@ resource "aws_eks_cluster" "this" {
5676
content {
5777
outpost_arns = outpost_config.value.outposts
5878

59-
control_plane_instance_type = outpost_config.value.control_plane_instance_type
79+
control_plane_instance_type = outpost_config.value.control_plane.instance_type
6080

6181
dynamic "control_plane_placement" {
62-
for_each = outpost_config.value.control_plane_placement_group != null ? [outpost_config.value.control_plane_placement_group] : []
82+
for_each = outpost_config.value.control.plane_placement_group != null ? [outpost_config.value.control_plane.placement_group] : []
6383

6484
content {
6585
group_name = control_plane_placement.value
@@ -71,6 +91,38 @@ resource "aws_eks_cluster" "this" {
7191
kubernetes_network_config {
7292
service_ipv4_cidr = var.kubernetes_network_config.service_ipv4_cidr
7393
ip_family = local.ip_family[var.kubernetes_network_config.ip_family]
94+
95+
dynamic "elastic_load_balancing" {
96+
for_each = var.auto_mode.network.elastic_load_balancing.enabled ? [var.auto_mode.network.elastic_load_balancing] : []
97+
98+
content {
99+
enabled = elastic_load_balancing.value.enabled
100+
}
101+
}
102+
}
103+
104+
dynamic "remote_network_config" {
105+
for_each = (length(var.remote_network_config.node_ipv4_cidrs) > 0 || length(var.remote_network_config.pod_ipv4_cidrs) > 0
106+
? [var.remote_network_config]
107+
: []
108+
)
109+
110+
content {
111+
dynamic "remote_node_networks" {
112+
for_each = length(remote_network_config.value.node_ipv4_cidrs) > 0 ? ["go"] : []
113+
114+
content {
115+
cidrs = remote_network_config.value.node_ipv4_cidrs
116+
}
117+
}
118+
dynamic "remote_pod_networks" {
119+
for_each = length(remote_network_config.value.pod_ipv4_cidrs) > 0 ? ["go"] : []
120+
121+
content {
122+
cidrs = remote_network_config.value.pod_ipv4_cidrs
123+
}
124+
}
125+
}
74126
}
75127

76128

@@ -93,6 +145,38 @@ resource "aws_eks_cluster" "this" {
93145
}
94146
}
95147

148+
149+
## Auto-mode Only
150+
dynamic "compute_config" {
151+
for_each = var.auto_mode.compute.enabled ? [var.auto_mode.compute] : []
152+
153+
content {
154+
enabled = compute_config.value.enabled
155+
node_pools = compute_config.value.builtin_node_pools
156+
node_role_arn = (compute_config.value.enabled
157+
? (compute_config.value.node_role != null
158+
? compute_config.value.node_role
159+
: one(module.role__node[*].arn)
160+
) : null
161+
)
162+
}
163+
}
164+
165+
dynamic "storage_config" {
166+
for_each = var.auto_mode.storage.block_storage.enabled ? [var.auto_mode.storage] : []
167+
168+
content {
169+
dynamic "block_storage" {
170+
for_each = storage_config.value.block_storage.enabled ? [storage_config.value.block_storage] : []
171+
172+
content {
173+
enabled = block_storage.value.enabled
174+
}
175+
}
176+
}
177+
}
178+
179+
96180
timeouts {
97181
create = var.timeouts.create
98182
update = var.timeouts.update

modules/eks-cluster/migrations.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 2025-11-17: Make OIDC provider for IRSA to be optional
2+
moved {
3+
from = module.oidc_provider.aws_iam_openid_connect_provider.this
4+
to = module.oidc_provider[0].aws_iam_openid_connect_provider.this
5+
}
6+
17
# 2023-11-10: Add variable to decide whether to create IAM role for EKS node
28
moved {
39
from = module.role__node

modules/eks-cluster/oidc-providers.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ resource "aws_eks_identity_provider_config" "this" {
88
provider.name => provider
99
}
1010

11+
region = var.region
12+
1113
cluster_name = aws_eks_cluster.this.name
1214

1315
oidc {

modules/eks-cluster/outputs.tf

Lines changed: 83 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
output "region" {
2+
description = "The AWS region this module resources resides in."
3+
value = aws_eks_cluster.this.region
4+
}
5+
16
output "name" {
27
description = "The name of the cluster."
38
value = aws_eks_cluster.this.name
@@ -23,11 +28,47 @@ output "platform_version" {
2328
value = aws_eks_cluster.this.platform_version
2429
}
2530

31+
output "upgrade_policy" {
32+
description = "The upgrade policy for the cluster."
33+
value = {
34+
force_upgrade = aws_eks_cluster.this.force_update_version
35+
support_type = aws_eks_cluster.this.upgrade_policy[0].support_type
36+
}
37+
}
38+
2639
output "status" {
2740
description = "The status of the EKS cluster. One of `CREATING`, `ACTIVE`, `DELETING`, `FAILED`."
2841
value = aws_eks_cluster.this.status
2942
}
3043

44+
output "arc_zonal_shift" {
45+
description = "The configurations of ARC zonal shift for the EKS cluster."
46+
value = {
47+
enabled = try(aws_eks_cluster.this.zonal_shift_config[0].enabled, false)
48+
}
49+
}
50+
51+
output "auto_mode" {
52+
description = "The configuration for Auto-mode of the EKS cluster."
53+
value = {
54+
compute = {
55+
enabled = try(aws_eks_cluster.this.compute_config[0].enabled, false)
56+
builtin_node_pools = try(aws_eks_cluster.this.compute_config[0].node_pools, [])
57+
node_role = try(aws_eks_cluster.this.compute_config[0].node_role_arn, null)
58+
}
59+
network = {
60+
elastic_load_balancing = {
61+
enabled = try(aws_eks_cluster.this.kubernetes_network_config[0].elastic_load_balancing[0].enabled, false)
62+
}
63+
}
64+
storage = {
65+
block_storage = {
66+
enabled = try(aws_eks_cluster.this.storage_config[0].block_storage[0].enabled, false)
67+
}
68+
}
69+
}
70+
}
71+
3172
output "vpc_id" {
3273
description = "The ID of VPC associated with the cluster."
3374
value = aws_eks_cluster.this.vpc_config[0].vpc_id
@@ -75,15 +116,18 @@ output "outpost_config" {
75116
description = <<EOF
76117
The configurations of the outpost for the EKS cluster.
77118
`outposts` - The list of the Outposts ARNs.
78-
`control_plane_instance_type` - The EC2 instance type of the local EKS control plane node on Outposts.
79-
`control_plane_placement_group` - The name of the placement group for the EKS control plane node on Outposts.
119+
`control_plane` - The configurations of the local EKS control plane node on Outposts.
120+
`instance_type` - The EC2 instance type of the local EKS control plane node on Outposts.
121+
`placement_group` - The name of the placement group for the EKS control plane node on Outposts.
80122
EOF
81123
value = (var.outpost_config != null
82124
? {
83-
outposts = aws_eks_cluster.this.outpost_config[0].outpost_arns
84-
cluster_id = aws_eks_cluster.this.cluster_id
85-
control_plane_instance_type = aws_eks_cluster.this.outpost_config[0].control_plane_instance_type
86-
control_plane_placement_group = one(aws_eks_cluster.this.outpost_config[0].control_plane_placement[*].group_name)
125+
outposts = aws_eks_cluster.this.outpost_config[0].outpost_arns
126+
cluster_id = aws_eks_cluster.this.cluster_id
127+
control_plane = {
128+
instance_type = aws_eks_cluster.this.outpost_config[0].control_plane_instance_type
129+
placement_group = one(aws_eks_cluster.this.outpost_config[0].control_plane_placement[*].group_name)
130+
}
87131
}
88132
: null
89133
)
@@ -103,6 +147,18 @@ output "kubernetes_network_config" {
103147
}
104148
}
105149

150+
output "remote_network_config" {
151+
description = <<EOF
152+
The configurations of remote network for the EKS Hybrid nodes.
153+
`node_ipv4_cidrs` - A set of IPv4 CIDR blocks for remote nodes.
154+
`pod_ipv4_cidrs` - A set of IPv4 CIDR blocks for remote pods.
155+
EOF
156+
value = {
157+
node_ipv4_cidrs = try(aws_eks_cluster.this.remote_network_config[0].remote_node_networks[0].cidrs, [])
158+
pod_ipv4_cidrs = try(aws_eks_cluster.this.remote_network_config[0].remote_pod_networks[0].cidrs, [])
159+
}
160+
}
161+
106162
output "authentication_mode" {
107163
description = "The authentication mode for the cluster."
108164
value = aws_eks_cluster.this.access_config[0].authentication_mode
@@ -141,27 +197,33 @@ output "default_node_role" {
141197
output "irsa_oidc_provider" {
142198
description = <<EOF
143199
The configurations of the OIDC provider for IRSA (IAM Roles for Service Accounts).
200+
`enabled` - Whether to create the IAM OIDC provider for the EKS cluster to use IAM Roles for Service Accounts (IRSA).
144201
`arn` - The ARN assigned by AWS for this provider.
145202
`url` - The URL of the identity provider.
146203
`urn` - The URN of the identity provider.
147204
`audiences` - A list of audiences (also known as client IDs) for the IAM OIDC provider.
148205
EOF
149206
value = {
150-
arn = module.oidc_provider.arn
207+
enabled = var.irsa_oidc_provider.enabled
151208
url = aws_eks_cluster.this.identity[0].oidc[0].issuer
152-
urn = module.oidc_provider.urn
153-
audiences = module.oidc_provider.audiences
209+
arn = one(module.oidc_provider[*].arn)
210+
urn = one(module.oidc_provider[*].urn)
211+
audiences = one(module.oidc_provider[*].audiences)
154212
}
155213
}
156214

157215
output "logging" {
158216
description = "The configurations of the control plane logging."
159217
value = {
218+
enabled = var.logging.enabled
160219
log_types = aws_eks_cluster.this.enabled_cluster_log_types
161-
cloudwatch_log_group = {
162-
arn = data.aws_cloudwatch_log_group.this.arn
163-
name = data.aws_cloudwatch_log_group.this.name
164-
}
220+
cloudwatch_log_group = (var.logging.enabled
221+
? {
222+
arn = data.aws_cloudwatch_log_group.this[0].arn
223+
name = data.aws_cloudwatch_log_group.this[0].name
224+
}
225+
: null
226+
)
165227
}
166228
}
167229

@@ -190,14 +252,6 @@ output "created_at" {
190252
value = aws_eks_cluster.this.created_at
191253
}
192254

193-
# output "debug" {
194-
# value = {
195-
# for k, v in aws_eks_cluster.this :
196-
# k => v
197-
# if !contains(["arn", "access_config", "certificate_authority", "tags", "tags_all", "created_at", "role_arn", "name", "status", "version", "timeouts", "platform_version", "kubernetes_network_config", "id", "endpoint", "encryption_config", "outpost_config", "identity", "vpc_config", "enabled_cluster_log_types", "cluster_id"], k)
198-
# }
199-
# }
200-
201255
output "resource_group" {
202256
description = "The resource group created to manage resources in this module."
203257
value = merge(
@@ -213,3 +267,11 @@ output "resource_group" {
213267
)
214268
)
215269
}
270+
271+
# output "debug" {
272+
# value = {
273+
# for k, v in aws_eks_cluster.this :
274+
# k => v
275+
# if !contains(["arn", "access_config", "certificate_authority", "tags", "tags_all", "created_at", "role_arn", "name", "status", "version", "timeouts", "platform_version", "kubernetes_network_config", "id", "endpoint", "encryption_config", "outpost_config", "identity", "vpc_config", "enabled_cluster_log_types", "cluster_id", "deletion_protection", "region", "upgrade_policy", "force_update_version", "oidc", "remote_network_config", "bootstrap_self_managed_addons", "storage_config", "compute_config", "zonal_shift_config"], k)
276+
# }
277+
# }

0 commit comments

Comments
 (0)