Skip to content

Commit 8042619

Browse files
committed
fixup! Migrate cluster modules from map(map(string)) to map(object)
1 parent 91a53dd commit 8042619

15 files changed

Lines changed: 135 additions & 276 deletions

File tree

aws/_modules/eks/node_pool.tf

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@ module "node_pool" {
1111

1212
subnet_ids = var.vpc_legacy_node_subnets ? aws_subnet.current[*].id : aws_subnet.node_pool[*].id
1313

14-
instance_types = var.instance_types
15-
desired_size = var.desired_capacity
16-
max_size = var.max_size
17-
min_size = var.min_size
14+
instance_types = var.default_node_pool != null && var.default_node_pool.instance_types != null ? toset(var.default_node_pool.instance_types) : (var.default_node_pool != null && var.default_node_pool.instance_type != null ? toset([var.default_node_pool.instance_type]) : toset([]))
15+
desired_size = var.default_node_pool != null && var.default_node_pool.desired_capacity != null ? var.default_node_pool.desired_capacity : 1
16+
max_size = var.default_node_pool != null && var.default_node_pool.max_size != null ? var.default_node_pool.max_size : 1
17+
min_size = var.default_node_pool != null && var.default_node_pool.min_size != null ? var.default_node_pool.min_size : 1
1818

19-
disk_size = var.root_device_volume_size
19+
disk_size = var.default_node_pool != null && var.default_node_pool.root_device_volume_size != null ? var.default_node_pool.root_device_volume_size : 20
2020

21-
metadata_options = var.metadata_options
21+
metadata_options = var.default_node_pool != null ? var.default_node_pool.metadata_options : null
2222

2323
taints = var.taints
2424

25-
ami_type = var.worker_ami_type
26-
ami_release_version = var.worker_ami_release_version
25+
ami_type = var.default_node_pool != null ? var.default_node_pool.ami_type : null
26+
ami_release_version = var.default_node_pool != null ? var.default_node_pool.ami_release_version : null
2727

28-
tags = var.additional_node_tags
28+
tags = var.default_node_pool != null && var.default_node_pool.additional_node_tags != null ? var.default_node_pool.additional_node_tags : {}
2929

3030
kubernetes_version = aws_eks_cluster.current.version
3131

aws/_modules/eks/variables.tf

Lines changed: 22 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -76,46 +76,28 @@ variable "vpc_subnet_map_public_ip" {
7676
nullable = false
7777
}
7878

79-
variable "instance_types" {
80-
description = "Set of AWS instance types to use for nodes."
81-
type = set(string)
82-
default = []
83-
nullable = false
84-
}
85-
86-
variable "desired_capacity" {
87-
description = "Desired number of worker nodes."
88-
type = number
89-
default = 1
90-
nullable = false
91-
}
92-
93-
variable "max_size" {
94-
description = "Maximum number of worker nodes."
95-
type = number
96-
default = 1
97-
nullable = false
98-
}
99-
100-
variable "min_size" {
101-
description = "Minimum number of worker nodes."
102-
type = number
103-
default = 1
104-
nullable = false
105-
}
106-
107-
variable "root_device_encrypted" {
108-
type = bool
109-
default = true
110-
description = "Whether to encrypt root device volumes of worker nodes."
111-
nullable = false
112-
}
113-
114-
variable "root_device_volume_size" {
115-
type = number
116-
default = 20
117-
description = "Size in GB for root device volumes of worker nodes."
118-
nullable = false
79+
variable "default_node_pool" {
80+
type = object({
81+
instance_type = optional(string)
82+
instance_types = optional(list(string))
83+
desired_capacity = optional(number)
84+
max_size = optional(number)
85+
min_size = optional(number)
86+
metadata_options = optional(object({
87+
http_endpoint = optional(string)
88+
http_tokens = optional(string)
89+
http_put_response_hop_limit = optional(number)
90+
http_protocol_ipv6 = optional(string)
91+
instance_metadata_tags = optional(string)
92+
}))
93+
additional_node_tags = optional(map(string))
94+
root_device_volume_size = optional(number)
95+
root_device_encrypted = optional(bool)
96+
ami_type = optional(string)
97+
ami_release_version = optional(string)
98+
})
99+
description = "Default node pool configuration."
100+
default = null
119101
}
120102

121103
variable "taints" {
@@ -127,13 +109,6 @@ variable "taints" {
127109
description = "Kubernetes taints to set for node pool."
128110
}
129111

130-
variable "additional_node_tags" {
131-
type = map(string)
132-
default = {}
133-
description = "Additional AWS tags to set on the node pool."
134-
nullable = false
135-
}
136-
137112
variable "aws_auth_map_roles" {
138113
description = "mapRoles entries added to aws-auth configmap"
139114
type = string
@@ -209,24 +184,3 @@ variable "cluster_encryption_key_arn" {
209184
type = string
210185
description = "Arn of an AWS KMS symmetric key to be used for encryption of kubernetes resources."
211186
}
212-
213-
variable "worker_ami_type" {
214-
type = string
215-
description = "AMI type to use for nodes. Defaults to automatically determined based on instance type (AL2023_x86_64_STANDARD, AL2023_ARM_64_STANDARD, AL2023_x86_64_NVIDIA or AL2023_ARM_64_NVIDIA)."
216-
}
217-
218-
variable "worker_ami_release_version" {
219-
type = string
220-
description = "AMI version of the EKS Node Group. Defaults to latest version for Kubernetes version. A list of release versions can be found in https://github.com/awslabs/amazon-eks-ami/blob/master/CHANGELOG.md"
221-
}
222-
223-
variable "metadata_options" {
224-
description = "EC2 metadata service options."
225-
type = object({
226-
http_endpoint = optional(string)
227-
http_tokens = optional(string)
228-
http_put_response_hop_limit = optional(number)
229-
http_protocol_ipv6 = optional(string)
230-
instance_metadata_tags = optional(string)
231-
})
232-
}

aws/cluster/main.tf

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,9 @@ module "cluster" {
4141
vpc_legacy_node_subnets = local.cfg["cluster_vpc_legacy_node_subnets"]
4242
vpc_subnet_map_public_ip = local.cfg["cluster_vpc_subnet_map_public_ip"]
4343

44-
instance_types = local.cfg["cluster_instance_types"] != null ? toset(local.cfg["cluster_instance_types"]) : (local.cfg["cluster_instance_type"] != null ? toset([local.cfg["cluster_instance_type"]]) : toset([]))
45-
desired_capacity = local.cfg["cluster_desired_capacity"]
46-
max_size = local.cfg["cluster_max_size"]
47-
min_size = local.cfg["cluster_min_size"]
48-
cluster_version = local.cfg["cluster_version"]
44+
default_node_pool = local.cfg["default_node_pool"]
4945

50-
metadata_options = local.cfg["metadata_options"]
51-
52-
root_device_encrypted = local.cfg["worker_root_device_encrypted"]
53-
root_device_volume_size = local.cfg["worker_root_device_volume_size"]
54-
55-
additional_node_tags = local.cfg["cluster_additional_node_tags"]
46+
cluster_version = local.cfg["cluster_version"]
5647

5748
aws_auth_map_roles = local.cfg["cluster_aws_auth_map_roles"]
5849
aws_auth_map_users = local.cfg["cluster_aws_auth_map_users"]
@@ -71,8 +62,5 @@ module "cluster" {
7162

7263
cluster_encryption_key_arn = local.cfg["cluster_encryption_key_arn"]
7364

74-
worker_ami_type = local.cfg["worker_ami_type"]
75-
worker_ami_release_version = local.cfg["worker_ami_release_version"]
76-
7765
taints = toset([])
7866
}

aws/cluster/variables.tf

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
variable "configuration" {
22
type = map(object({
33
# Required attributes
4-
name_prefix = optional(string)
5-
base_domain = optional(string)
6-
cluster_desired_capacity = optional(number)
7-
cluster_max_size = optional(number)
8-
cluster_min_size = optional(number)
4+
name_prefix = optional(string)
5+
base_domain = optional(string)
96

107
# Optional attributes with defaults
118
cluster_availability_zones = optional(list(string))
@@ -20,27 +17,28 @@ variable "configuration" {
2017
cluster_vpc_legacy_node_subnets = optional(bool)
2118
cluster_vpc_subnet_map_public_ip = optional(bool)
2219

23-
cluster_instance_type = optional(string)
24-
cluster_instance_types = optional(list(string))
25-
26-
metadata_options = optional(object({
27-
http_endpoint = optional(string)
28-
http_tokens = optional(string)
29-
http_put_response_hop_limit = optional(number)
30-
http_protocol_ipv6 = optional(string)
31-
instance_metadata_tags = optional(string)
20+
default_node_pool = optional(object({
21+
desired_capacity = optional(number)
22+
max_size = optional(number)
23+
min_size = optional(number)
24+
instance_type = optional(string)
25+
instance_types = optional(list(string))
26+
metadata_options = optional(object({
27+
http_endpoint = optional(string)
28+
http_tokens = optional(string)
29+
http_put_response_hop_limit = optional(number)
30+
http_protocol_ipv6 = optional(string)
31+
instance_metadata_tags = optional(string)
32+
}))
33+
additional_node_tags = optional(map(string))
34+
root_device_volume_size = optional(number)
35+
root_device_encrypted = optional(bool)
36+
ami_type = optional(string)
37+
ami_release_version = optional(string)
3238
}))
3339

34-
cluster_additional_node_tags = optional(map(string))
35-
3640
cluster_version = optional(string)
3741

38-
worker_root_device_volume_size = optional(number)
39-
worker_root_device_encrypted = optional(bool)
40-
41-
worker_ami_type = optional(string)
42-
worker_ami_release_version = optional(string)
43-
4442
cluster_aws_auth_map_roles = optional(string)
4543
cluster_aws_auth_map_users = optional(string)
4644
cluster_aws_auth_map_accounts = optional(string)

google/_modules/gke/cluster.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ resource "google_container_cluster" "current" {
1313
channel = var.release_channel
1414
}
1515

16-
remove_default_node_pool = var.remove_default_node_pool
17-
initial_node_count = var.initial_node_count
16+
remove_default_node_pool = var.default_node_pool != null && var.default_node_pool.remove_default_node_pool != null ? var.default_node_pool.remove_default_node_pool : true
17+
initial_node_count = var.default_node_pool != null && var.default_node_pool.initial_node_count != null ? var.default_node_pool.initial_node_count : 1
1818

1919
master_auth {
2020
client_certificate_config {

google/_modules/gke/node_pool.tf

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,25 @@ module "node_pool" {
1313
metadata_tags = var.metadata_tags
1414
metadata_labels = var.metadata_labels
1515

16-
initial_node_count = var.initial_node_count
17-
min_node_count = var.min_node_count
18-
max_node_count = var.max_node_count
16+
initial_node_count = var.default_node_pool != null && var.default_node_pool.initial_node_count != null ? var.default_node_pool.initial_node_count : 1
17+
min_node_count = var.default_node_pool != null && var.default_node_pool.min_node_count != null ? var.default_node_pool.min_node_count : 1
18+
max_node_count = var.default_node_pool != null && var.default_node_pool.max_node_count != null ? var.default_node_pool.max_node_count : 1
1919
node_locations = var.node_locations
20-
location_policy = var.location_policy
20+
location_policy = var.default_node_pool != null && var.default_node_pool.node_location_policy != null ? var.default_node_pool.node_location_policy : null
2121

22-
extra_oauth_scopes = var.extra_oauth_scopes
22+
extra_oauth_scopes = var.default_node_pool != null && var.default_node_pool.extra_oauth_scopes != null ? var.default_node_pool.extra_oauth_scopes : []
2323

24-
disk_size_gb = var.disk_size_gb
25-
disk_type = var.disk_type
26-
image_type = var.image_type
27-
machine_type = var.machine_type
24+
disk_size_gb = var.default_node_pool != null && var.default_node_pool.disk_size_gb != null ? var.default_node_pool.disk_size_gb : 100
25+
disk_type = var.default_node_pool != null && var.default_node_pool.disk_type != null ? var.default_node_pool.disk_type : "pd-standard"
26+
image_type = var.default_node_pool != null && var.default_node_pool.image_type != null ? var.default_node_pool.image_type : "COS_containerd"
27+
machine_type = var.default_node_pool != null && var.default_node_pool.machine_type != null ? var.default_node_pool.machine_type : ""
2828

2929
# Whether to use preemptible nodes for this node pool
30-
preemptible = var.preemptible
30+
preemptible = var.default_node_pool != null && var.default_node_pool.preemptible != null ? var.default_node_pool.preemptible : false
3131
# Whether the nodes will be automatically repaired
32-
auto_repair = var.auto_repair
32+
auto_repair = var.default_node_pool != null && var.default_node_pool.auto_repair != null ? var.default_node_pool.auto_repair : true
3333
# Whether the nodes will be automatically upgraded
34-
auto_upgrade = var.auto_upgrade
34+
auto_upgrade = var.default_node_pool != null && var.default_node_pool.auto_upgrade != null ? var.default_node_pool.auto_upgrade : true
3535

3636
node_workload_metadata_config = var.node_workload_metadata_config
3737

0 commit comments

Comments
 (0)