Skip to content

Commit 24cc7c0

Browse files
Merge pull request #75 from laverya/use-static-not-computed-worker-group-count
Use static not computed worker group count
2 parents 6e0cf72 + 5f8df2e commit 24cc7c0

File tree

6 files changed

+27
-15
lines changed

6 files changed

+27
-15
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ project adheres to [Semantic Versioning](http://semver.org/).
99

1010
### Added
1111

12-
- manage eks workers' root volume size and type
13-
- `workers_asg_names` added to outputs.
12+
- manage eks workers' root volume size and type.
13+
- `workers_asg_names` added to outputs. (kudos to @laverya)
14+
- New top level variable `worker_group_count` added to replace the use of `length(var.worker_groups)`. This allows using computed values as part of worker group configs. (complaints to @laverya)
1415

1516
### Changed
1617

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a
110110
| subnets | A list of subnets to place the EKS cluster and workers within. | list | - | yes |
111111
| tags | A map of tags to add to all resources. | map | `<map>` | no |
112112
| vpc_id | VPC where the cluster and workers will be deployed. | string | - | yes |
113+
| worker_group_count | The number of maps contained within the worker_groups list. | string | `1` | no |
113114
| worker_groups | A list of maps defining worker group configurations. See workers_group_defaults for valid keys. | list | `<list>` | no |
114115
| worker_security_group_id | If provided, all workers will be attached to this security group. If not given, a security group will be created with necessary ingres/egress to work with the EKS cluster. | string | `` | no |
115116
| worker_sg_ingress_from_port | Minimum port number from which pods will accept communication. Must be changed to a lower value if some pods in your cluster will expose a port lower than 1025 (e.g. 22, 80, or 443). | string | `1025` | no |

data.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ EOF
7575

7676
data "template_file" "userdata" {
7777
template = "${file("${path.module}/templates/userdata.sh.tpl")}"
78-
count = "${length(var.worker_groups)}"
78+
count = "${var.worker_group_count}"
7979

8080
vars {
8181
region = "${data.aws_region.current.name}"

examples/eks_test_fixture/main.tf

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,21 @@ locals {
2424
# "asg_min_size", "2",
2525
# "instance_type", "m4.xlarge",
2626
# "name", "worker_group_a",
27+
# "subnets", "${join(",", module.vpc.private_subnets)}",
2728
# ),
2829
# map("asg_desired_capacity", "1",
2930
# "asg_max_size", "5",
3031
# "asg_min_size", "1",
3132
# "instance_type", "m4.2xlarge",
3233
# "name", "worker_group_b",
34+
# "subnets", "${join(",", module.vpc.private_subnets)}",
3335
# ),
3436
# )}"
3537

3638
worker_groups = "${list(
3739
map("instance_type","t2.small",
38-
"additional_userdata","echo foo bar"
40+
"additional_userdata","echo foo bar",
41+
"subnets", "${join(",", module.vpc.private_subnets)}",
3942
),
4043
)}"
4144
tags = "${map("Environment", "test",
@@ -64,13 +67,14 @@ module "vpc" {
6467
}
6568

6669
module "eks" {
67-
source = "../.."
68-
cluster_name = "${local.cluster_name}"
69-
subnets = "${module.vpc.public_subnets}"
70-
tags = "${local.tags}"
71-
vpc_id = "${module.vpc.vpc_id}"
72-
worker_groups = "${local.worker_groups}"
73-
map_roles = "${var.map_roles}"
74-
map_users = "${var.map_users}"
75-
map_accounts = "${var.map_accounts}"
70+
source = "../.."
71+
cluster_name = "${local.cluster_name}"
72+
subnets = ["${module.vpc.public_subnets}", "${module.vpc.private_subnets}"]
73+
tags = "${local.tags}"
74+
vpc_id = "${module.vpc.vpc_id}"
75+
worker_groups = "${local.worker_groups}"
76+
worker_group_count = "1"
77+
map_roles = "${var.map_roles}"
78+
map_users = "${var.map_users}"
79+
map_accounts = "${var.map_accounts}"
7680
}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ variable "worker_groups" {
7474
}]
7575
}
7676

77+
variable "worker_group_count" {
78+
description = "The number of maps contained within the worker_groups list."
79+
type = "string"
80+
default = "1"
81+
}
82+
7783
variable "workers_group_defaults" {
7884
description = "Default values for target groups as defined by the list of maps."
7985
type = "map"

workers.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ resource "aws_autoscaling_group" "workers" {
55
min_size = "${lookup(var.worker_groups[count.index], "asg_min_size",lookup(var.workers_group_defaults, "asg_min_size"))}"
66
launch_configuration = "${element(aws_launch_configuration.workers.*.id, count.index)}"
77
vpc_zone_identifier = ["${split(",", coalesce(lookup(var.worker_groups[count.index], "subnets", ""), join(",", var.subnets)))}"]
8-
count = "${length(var.worker_groups)}"
8+
count = "${var.worker_group_count}"
99

1010
tags = ["${concat(
1111
list(
@@ -30,7 +30,7 @@ resource "aws_launch_configuration" "workers" {
3030
key_name = "${lookup(var.worker_groups[count.index], "key_name", lookup(var.workers_group_defaults, "key_name"))}"
3131
user_data_base64 = "${base64encode(element(data.template_file.userdata.*.rendered, count.index))}"
3232
ebs_optimized = "${lookup(var.worker_groups[count.index], "ebs_optimized", lookup(local.ebs_optimized, lookup(var.worker_groups[count.index], "instance_type", lookup(var.workers_group_defaults, "instance_type")), false))}"
33-
count = "${length(var.worker_groups)}"
33+
count = "${var.worker_group_count}"
3434

3535
lifecycle {
3636
create_before_destroy = true

0 commit comments

Comments
 (0)