Skip to content

Commit 9de3993

Browse files
committed
fixup! Migrate cluster modules from map(map(string)) to map(object)
1 parent bec5fe1 commit 9de3993

17 files changed

Lines changed: 297 additions & 313 deletions

File tree

aws/_modules/eks/aws_iam_authenticator.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ resource "kubernetes_config_map" "current" {
1111
groups:
1212
- system:bootstrappers
1313
- system:nodes
14-
${var.aws_auth_map_roles}
14+
${var.aws_auth_map_roles != null ? var.aws_auth_map_roles : ""}
1515
MAPROLES
1616

1717
mapUsers = var.aws_auth_map_users

aws/_modules/eks/node_pool.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ module "node_pool" {
2727

2828
tags = var.default_node_pool != null && var.default_node_pool.additional_node_tags != null ? var.default_node_pool.additional_node_tags : {}
2929

30+
labels = var.default_node_pool.labels
31+
32+
3033
kubernetes_version = aws_eks_cluster.current.version
3134

3235
# force node_pool to depend on aws-auth configmap

aws/_modules/eks/node_pool/variables.tf

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ variable "min_size" {
4545

4646
variable "disk_size" {
4747
type = number
48-
default = 20
4948
description = "Size in GB of node root volumes."
50-
nullable = false
5149
}
5250

5351
variable "subnet_ids" {
@@ -72,15 +70,11 @@ variable "taints" {
7270
variable "tags" {
7371
type = map(string)
7472
description = "AWS tags to set on the node pool. Merged with Kubestack default tags."
75-
default = {}
76-
nullable = false
7773
}
7874

7975
variable "labels" {
8076
type = map(string)
8177
description = "Kubernetes labels to set on the nodes created by the node pool. Merged with Kubestack default labels."
82-
default = {}
83-
nullable = false
8478
}
8579

8680
variable "ami_type" {
@@ -101,10 +95,10 @@ variable "kubernetes_version" {
10195
variable "metadata_options" {
10296
description = "EC2 metadata service options."
10397
type = object({
104-
http_endpoint = optional(string)
105-
http_tokens = optional(string)
106-
http_put_response_hop_limit = optional(number)
107-
http_protocol_ipv6 = optional(string)
108-
instance_metadata_tags = optional(string)
98+
http_endpoint = string
99+
http_tokens = string
100+
http_put_response_hop_limit = number
101+
http_protocol_ipv6 = string
102+
instance_metadata_tags = string
109103
})
110104
}

aws/_modules/eks/variables.tf

Lines changed: 32 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -18,77 +18,67 @@ variable "kubernetes_version" {
1818
variable "enabled_cluster_log_types" {
1919
type = list(string)
2020
description = "List of cluster log types to enable."
21-
default = ["api", "audit", "authenticator", "controllerManager", "scheduler"]
22-
nullable = false
2321
}
2422

2523
variable "vpc_config" {
2624
type = object({
27-
cidr = optional(string, "10.0.0.0/16")
28-
control_subnet_newbits = optional(string, "8")
29-
node_subnet_newbits = optional(string, "4")
30-
node_subnet_number_offset = optional(string, "1")
31-
legacy_node_subnets = optional(bool, false)
32-
dns_hostnames = optional(bool, false)
33-
dns_support = optional(bool, true)
34-
subnet_map_public_ip = optional(bool, true)
35-
endpoint_private_access = optional(bool, false)
36-
endpoint_public_access = optional(bool, true)
37-
public_access_cidrs = optional(list(string))
25+
cidr = string
26+
control_subnet_newbits = string
27+
node_subnet_newbits = string
28+
node_subnet_number_offset = string
29+
legacy_node_subnets = bool
30+
dns_hostnames = bool
31+
dns_support = bool
32+
subnet_map_public_ip = bool
33+
endpoint_private_access = bool
34+
endpoint_public_access = bool
35+
public_access_cidrs = list(string)
3836
})
3937
description = "VPC configuration for the EKS cluster matching vpc_config block structure."
40-
default = {}
41-
nullable = false
4238
}
4339

4440
variable "kubernetes_network_config" {
4541
type = object({
46-
service_ipv4_cidr = optional(string)
42+
service_ipv4_cidr = string
4743
})
4844
description = "Kubernetes network configuration matching kubernetes_network_config block."
49-
default = {}
50-
nullable = false
5145
}
5246

5347
variable "encryption_config" {
5448
type = object({
55-
provider_key_arn = optional(string)
49+
provider_key_arn = string
5650
})
5751
description = "Encryption configuration matching encryption_config block. Set provider_key_arn to enable encryption."
58-
default = {}
59-
nullable = false
6052
}
6153

6254
variable "availability_zones" {
6355
description = "List of availability zones for the cluster."
6456
type = list(string)
65-
default = []
66-
nullable = false
6757
}
6858

6959
variable "default_node_pool" {
7060
type = object({
71-
instance_types = optional(list(string))
72-
desired_capacity = optional(number)
73-
max_size = optional(number)
74-
min_size = optional(number)
75-
launch_template = optional(object({
76-
metadata_options = optional(object({
77-
http_endpoint = optional(string)
78-
http_tokens = optional(string)
79-
http_put_response_hop_limit = optional(number)
80-
http_protocol_ipv6 = optional(string)
81-
instance_metadata_tags = optional(string)
82-
}))
83-
}))
84-
additional_node_tags = optional(map(string))
85-
root_device_volume_size = optional(number)
86-
root_device_encrypted = optional(bool)
87-
ami_type = optional(string)
88-
ami_release_version = optional(string)
61+
instance_types = list(string)
62+
desired_capacity = number
63+
max_size = number
64+
min_size = number
65+
launch_template = object({
66+
metadata_options = object({
67+
http_endpoint = string
68+
http_tokens = string
69+
http_put_response_hop_limit = number
70+
http_protocol_ipv6 = string
71+
instance_metadata_tags = string
72+
})
73+
})
74+
additional_node_tags = map(string)
75+
labels = map(string)
76+
root_device_volume_size = number
77+
root_device_encrypted = bool
78+
ami_type = string
79+
ami_release_version = string
8980
})
9081
description = "Default node pool configuration."
91-
default = null
9282
}
9383

9484
variable "taints" {
@@ -103,34 +93,24 @@ variable "taints" {
10393
variable "aws_auth_map_roles" {
10494
description = "mapRoles entries added to aws-auth configmap"
10595
type = string
106-
default = ""
107-
nullable = false
10896
}
10997

11098
variable "aws_auth_map_users" {
11199
description = "mapUsers entries added to aws-auth configmap"
112100
type = string
113-
default = ""
114-
nullable = false
115101
}
116102

117103
variable "aws_auth_map_accounts" {
118104
description = "mapAccounts entries added to aws-auth configmap"
119105
type = string
120-
default = ""
121-
nullable = false
122106
}
123107

124108
variable "disable_default_ingress" {
125109
type = bool
126110
description = "Whether to disable the default ingress."
127-
default = false
128-
nullable = false
129111
}
130112

131113
variable "disable_openid_connect_provider" {
132114
type = bool
133115
description = "Whether to disable the OpenID connect provider."
134-
default = false
135-
nullable = false
136116
}

aws/cluster/main.tf

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ module "configuration" {
66

77
locals {
88
cfg = module.configuration.merged[terraform.workspace]
9+
10+
default_node_pool_cfg = local.cfg["default_node_pool"]
11+
default_node_pool_metadata_options_cfg = try(local.default_node_pool_cfg["metadata_options"], null)
912
}
1013

1114
data "aws_region" "current" {
@@ -28,19 +31,19 @@ module "cluster" {
2831

2932
kubernetes_version = local.cfg["cluster_version"]
3033

31-
availability_zones = local.cfg["cluster_availability_zones"]
34+
availability_zones = try(coalesce(local.cfg["cluster_availability_zones"], null), [])
3235

3336
vpc_config = {
34-
cidr = local.cfg["cluster_vpc_cidr"]
35-
control_subnet_newbits = local.cfg["cluster_vpc_control_subnet_newbits"]
36-
node_subnet_newbits = local.cfg["cluster_vpc_node_subnet_newbits"]
37-
node_subnet_number_offset = local.cfg["cluster_vpc_node_subnet_number_offset"]
38-
legacy_node_subnets = local.cfg["cluster_vpc_legacy_node_subnets"]
39-
dns_hostnames = local.cfg["cluster_vpc_dns_hostnames"]
40-
dns_support = local.cfg["cluster_vpc_dns_support"]
41-
subnet_map_public_ip = local.cfg["cluster_vpc_subnet_map_public_ip"]
42-
endpoint_private_access = local.cfg["cluster_endpoint_private_access"]
43-
endpoint_public_access = local.cfg["cluster_endpoint_public_access"]
37+
cidr = try(coalesce(local.cfg["cluster_vpc_cidr"], null), "10.0.0.0/16")
38+
control_subnet_newbits = try(coalesce(local.cfg["cluster_vpc_control_subnet_newbits"], null), "8")
39+
node_subnet_newbits = try(coalesce(local.cfg["cluster_vpc_node_subnet_newbits"], null), "4")
40+
node_subnet_number_offset = try(coalesce(local.cfg["cluster_vpc_node_subnet_number_offset"], null), "1")
41+
legacy_node_subnets = try(coalesce(local.cfg["cluster_vpc_legacy_node_subnets"], null), false)
42+
dns_hostnames = try(coalesce(local.cfg["cluster_vpc_dns_hostnames"], null), false)
43+
dns_support = try(coalesce(local.cfg["cluster_vpc_dns_support"], null), true)
44+
subnet_map_public_ip = try(coalesce(local.cfg["cluster_vpc_subnet_map_public_ip"], null), true)
45+
endpoint_private_access = try(coalesce(local.cfg["cluster_endpoint_private_access"], null), false)
46+
endpoint_public_access = try(coalesce(local.cfg["cluster_endpoint_public_access"], null), true)
4447
public_access_cidrs = local.cfg["cluster_public_access_cidrs"]
4548
}
4649

@@ -52,17 +55,37 @@ module "cluster" {
5255
provider_key_arn = local.cfg["cluster_encryption_key_arn"]
5356
}
5457

55-
enabled_cluster_log_types = local.cfg["enabled_cluster_log_types"]
56-
57-
default_node_pool = local.cfg["default_node_pool"]
58+
enabled_cluster_log_types = try(coalesce(local.cfg["enabled_cluster_log_types"], null), ["api", "audit", "authenticator", "controllerManager", "scheduler"])
59+
60+
default_node_pool = {
61+
instance_types = try(local.default_node_pool_cfg["instance_types"], null)
62+
desired_capacity = try(coalesce(local.default_node_pool_cfg["desired_capacity"], null), 1)
63+
max_size = try(coalesce(local.default_node_pool_cfg["max_size"], null), 1)
64+
min_size = try(coalesce(local.default_node_pool_cfg["min_size"], null), 1)
65+
launch_template = {
66+
metadata_options = try({
67+
http_endpoint = local.default_node_pool_metadata_options_cfg["http_endpoint"]
68+
http_tokens = local.default_node_pool_metadata_options_cfg["http_tokens"]
69+
http_put_response_hop_limit = local.default_node_pool_metadata_options_cfg["http_put_response_hop_limit"]
70+
http_protocol_ipv6 = local.default_node_pool_metadata_options_cfg["http_protocol_ipv6"]
71+
instance_metadata_tags = local.default_node_pool_metadata_options_cfg["instance_metadata_tags"]
72+
}, null)
73+
}
74+
additional_node_tags = try(local.default_node_pool_cfg["additional_node_tags"], null)
75+
labels = try(coalesce(local.default_node_pool_cfg["labels"], null), {})
76+
root_device_volume_size = try(coalesce(local.default_node_pool_cfg["root_device_volume_size"], null), 20)
77+
root_device_encrypted = try(local.default_node_pool_cfg["root_device_encrypted"], null)
78+
ami_type = try(local.default_node_pool_cfg["ami_type"], null)
79+
ami_release_version = try(local.default_node_pool_cfg["ami_release_version"], null)
80+
}
5881

5982
taints = toset([])
6083

61-
aws_auth_map_roles = local.cfg["cluster_aws_auth_map_roles"]
62-
aws_auth_map_users = local.cfg["cluster_aws_auth_map_users"]
63-
aws_auth_map_accounts = local.cfg["cluster_aws_auth_map_accounts"]
84+
aws_auth_map_roles = try(coalesce(local.cfg["cluster_aws_auth_map_roles"], null), "")
85+
aws_auth_map_users = try(coalesce(local.cfg["cluster_aws_auth_map_users"], null), "")
86+
aws_auth_map_accounts = try(coalesce(local.cfg["cluster_aws_auth_map_accounts"], null), "")
6487

65-
disable_default_ingress = local.cfg["disable_default_ingress"]
88+
disable_default_ingress = try(coalesce(local.cfg["disable_default_ingress"], null), false)
6689

67-
disable_openid_connect_provider = local.cfg["disable_openid_connect_provider"]
90+
disable_openid_connect_provider = try(coalesce(local.cfg["disable_openid_connect_provider"], null), false)
6891
}

aws/cluster/node-pool/main.tf

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module "node_pool" {
3434

3535
subnet_ids = local.vpc_subnet_newbits == null ? local.vpc_subnet_ids : aws_subnet.current[*].id
3636

37-
instance_types = local.cfg["instance_types"] == null ? toset([]) : toset(local.cfg["instance_types"])
37+
instance_types = try(toset(local.cfg["instance_types"]), toset([]))
3838
ami_release_version = lookup(local.cfg, "ami_release_version")
3939
desired_size = lookup(local.cfg, "desired_capacity")
4040
max_size = lookup(local.cfg, "max_size")
@@ -44,15 +44,16 @@ module "node_pool" {
4444

4545
kubernetes_version = data.aws_eks_cluster.current.version
4646

47-
disk_size = local.cfg["disk_size"]
47+
disk_size = try(coalesce(local.cfg["disk_size"], null), 20)
4848

4949
metadata_options = local.cfg["metadata_options"]
5050

51-
taints = local.cfg["taints"] == null ? toset([]) : local.cfg["taints"]
51+
taints = try(coalesce(local.cfg["taints"], null), toset([]))
5252

53-
tags = local.cfg["tags"]
53+
tags = try(coalesce(local.cfg["tags"], null), {})
5454

55-
labels = local.cfg["labels"]
55+
labels = try(coalesce(local.cfg["labels"], null), {})
5656

5757
depends-on-aws-auth = null
5858
}
59+

aws/cluster/variables.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ variable "configuration" {
3030
instance_metadata_tags = optional(string)
3131
}))
3232
additional_node_tags = optional(map(string))
33+
labels = optional(map(string))
3334
root_device_volume_size = optional(number)
3435
root_device_encrypted = optional(bool)
3536
ami_type = optional(string)

0 commit comments

Comments
 (0)