Skip to content

Commit d5582b6

Browse files
author
Grzegorz Lisowski
committed
- Worker locals/defaults moved to workers submodule
- Create separate defaults for node groups - Workers IAM management left outside of module as both node_group and worker_groups uses them
1 parent f887504 commit d5582b6

File tree

6 files changed

+28
-86
lines changed

6 files changed

+28
-86
lines changed

README.md

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ module "my-cluster" {
4949
subnets = ["subnet-abcde012", "subnet-bcde012a", "subnet-fghi345a"]
5050
vpc_id = "vpc-1234556abcdef"
5151
52-
worker_groups = [
53-
{
52+
worker_groups = {
53+
group = {
5454
instance_type = "m4.large"
5555
asg_max_size = 5
5656
}
57-
]
57+
}
5858
}
5959
```
6060
## Conditional creation
@@ -149,7 +149,6 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a
149149
| kubernetes | >= 1.11.1 |
150150
| local | >= 1.4 |
151151
| null | >= 2.1 |
152-
| random | >= 2.1 |
153152

154153
## Inputs
155154

@@ -203,8 +202,6 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a
203202
| worker\_create\_initial\_lifecycle\_hooks | Whether to create initial lifecycle hooks provided in worker groups. | `bool` | `false` | no |
204203
| worker\_create\_security\_group | Whether to create a security group for the workers or attach the workers to `worker_security_group_id`. | `bool` | `true` | no |
205204
| worker\_groups | A map of maps defining worker group configurations to be defined using AWS Launch Templates. See workers\_group\_defaults for valid keys. | `any` | `{}` | no |
206-
| worker\_groups\_launch\_template\_legacy | A list of maps defining worker group configurations to be defined using AWS Launch Templates. See workers\_group\_defaults for valid keys. This field is deprecated please use/switch to var.worker\_groups | `any` | `[]` | no |
207-
| worker\_groups\_legacy | A list of maps defining worker group configurations to be defined using AWS Launch Configurations. See workers\_group\_defaults for valid keys. This field is deprecated please use/switch to var.worker\_groups | `any` | `[]` | no |
208205
| 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 ingress/egress to work with the EKS cluster. | `string` | `""` | no |
209206
| 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). | `number` | `1025` | no |
210207
| workers\_additional\_policies | Additional policies to be added to workers | `list(string)` | `[]` | no |
@@ -233,17 +230,6 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a
233230
| node\_groups | Outputs from EKS node groups. Map of maps, keyed by var.node\_groups keys |
234231
| oidc\_provider\_arn | The ARN of the OIDC Provider if `enable_irsa = true`. |
235232
| worker\_groups | Outputs from EKS worker groups. Map of maps, keyed by var.worker\_groups keys |
236-
| worker\_iam\_instance\_profile\_arns | default IAM instance profile ARN for EKS worker groups |
237-
| worker\_iam\_instance\_profile\_names | default IAM instance profile name for EKS worker groups |
238-
| worker\_iam\_role\_arn | default IAM role ARN for EKS worker groups |
239-
| worker\_iam\_role\_name | default IAM role name for EKS worker groups |
240233
| worker\_security\_group\_id | Security group ID attached to the EKS workers. |
241-
| workers\_asg\_arns | IDs of the autoscaling groups containing workers. |
242-
| workers\_asg\_names | Names of the autoscaling groups containing workers. |
243-
| workers\_default\_ami\_id | ID of the default worker group AMI |
244-
| workers\_launch\_template\_arns | ARNs of the worker launch templates. |
245-
| workers\_launch\_template\_ids | IDs of the worker launch templates. |
246-
| workers\_launch\_template\_latest\_versions | Latest versions of the worker launch templates. |
247-
| workers\_user\_data | User data of worker groups |
248234

249235
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

examples/launch_templates/main.tf

Lines changed: 9 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ data "aws_eks_cluster" "cluster" {
2424
}
2525

2626
data "aws_eks_cluster_auth" "cluster" {
27-
name = module.eks.cluster_id
27+
name = "test-eks-lt-1oEOVXor" #module.eks.cluster_id
2828
}
2929

3030
provider "kubernetes" {
@@ -38,7 +38,7 @@ provider "kubernetes" {
3838
data "aws_availability_zones" "available" {}
3939

4040
locals {
41-
cluster_name = "module-eks-lt-${random_string.suffix.result}"
41+
cluster_name = "test-eks-lt-${random_string.suffix.result}"
4242
}
4343

4444
resource "random_string" "suffix" {
@@ -71,73 +71,20 @@ module "eks" {
7171
subnets = module.vpc.public_subnets
7272
vpc_id = module.vpc.vpc_id
7373

74-
create_eks = true
75-
76-
cluster_enabled_log_types = [
77-
"api",
78-
"audit",
79-
"authenticator",
80-
"controllerManager",
81-
"scheduler",
82-
]
74+
workers_group_defaults = {
75+
asg_recreate_on_change = true
76+
}
8377

8478
worker_groups = {
85-
common-workload-group = {
86-
instance_type = "t2.small"
87-
root_encrypted = true
88-
kubelet_extra_args = "--node-labels=node.kubernetes.io/role=node"
89-
90-
asg_desired_capacity = 1
91-
asg_max_size = 3
92-
asg_min_size = 1
93-
asg_force_delete = false
94-
protect_from_scale_in = false
95-
96-
enable_monitoring = true
97-
enabled_metrics = [
98-
"GroupMinSize",
99-
"GroupMaxSize",
100-
"GroupDesiredCapacity",
101-
"GroupInServiceInstances",
102-
"GroupPendingInstances",
103-
"GroupStandbyInstances",
104-
"GroupTerminatingInstances",
105-
"GroupTotalInstances"
106-
]
107-
108-
public_ip = true
109-
tags = [
110-
{
111-
key = "k8s.io/cluster-autoscaler/enabled"
112-
propagate_at_launch = "false"
113-
value = "true"
114-
},
115-
{
116-
key = "k8s.io/cluster-autoscaler/${local.cluster_name}"
117-
propagate_at_launch = "false"
118-
value = "true"
119-
}
120-
]
79+
worker-group-1 = {
80+
instance_type = "t2.small"
81+
asg_desired_capacity = 2
82+
public_ip = true
12183
},
12284
worker-group-2 = {
12385
instance_type = "t2.medium"
12486
asg_desired_capacity = 1
12587
public_ip = true
126-
127-
additional_ebs_volumes = [
128-
{
129-
block_device_name = "/dev/sdf"
130-
volume_size = 50
131-
}
132-
]
133-
},
134-
worker-group-spot = {
135-
override_instance_types = ["m5.large", "m5a.large", "m5d.large"]
136-
spot_instance_pools = 3
137-
asg_max_size = 3
138-
asg_desired_capacity = 1
139-
kubelet_extra_args = "--node-labels=node.kubernetes.io/lifecycle=spot"
140-
public_ip = true
14188
},
14289
}
14390

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
variable "region" {
2-
// default = "us-west-2"
32
default = "eu-central-1"
43
}
54

modules/node_groups/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ No requirements.
5454
| default\_iam\_role\_arn | ARN of the default IAM worker role to use if one is not specified in `var.node_groups` or `var.node_groups_defaults` | `string` | n/a | yes |
5555
| node\_groups | Map of maps of `eks_node_groups` to create. See "`node_groups` and `node_groups_defaults` keys" section in README.md for more details | `any` | `{}` | no |
5656
| node\_groups\_defaults | map of maps of node groups to create. See "`node_groups` and `node_groups_defaults` keys" section in README.md for more details | `any` | n/a | yes |
57+
| subnets | A list of subnets to place the EKS cluster and workers within. | `list(string)` | n/a | yes |
5758
| tags | A map of tags to add to all resources | `map(string)` | n/a | yes |
5859
| workers\_group\_defaults | Workers group defaults from parent | `any` | n/a | yes |
5960

modules/worker_groups/README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,25 @@ No requirements.
3737
| cluster\_auth\_base64 | Cluster auth data | `string` | n/a | yes |
3838
| cluster\_endpoint | Cluster endpojnt | `string` | n/a | yes |
3939
| cluster\_name | Cluster name | `string` | n/a | yes |
40-
| create\_eks | Controls if EKS resources should be created (it affects almost all resources) | `bool` | `true` | no |
41-
| default\_ami\_id\_linux | Default Linux AMI id. | `string` | n/a | yes |
42-
| default\_ami\_id\_windows | Default Windows AMI id. | `string` | n/a | yes |
40+
| cluster\_security\_group\_id | EKS cluster security group id. | `string` | n/a | yes |
41+
| cluster\_version | Kubernetes version to use for the EKS cluster. | `string` | n/a | yes |
42+
| create\_workers | Controls if EKS resources should be created (it affects almost all resources) | `bool` | `true` | no |
4343
| default\_iam\_role\_id | ARN of the default IAM worker role to use if one is not specified in `var.node_groups` or `var.node_groups_defaults` | `string` | n/a | yes |
44-
| ebs\_optimized\_not\_supported | List of instance types where ebs optimized is not supported. | `list(string)` | n/a | yes |
4544
| iam\_path | If provided, all IAM roles will be created on this path. | `string` | `"/"` | no |
4645
| manage\_worker\_iam\_resources | Whether to let the module manage worker IAM resources. If set to false, iam\_instance\_profile\_name must be specified for workers. | `bool` | `true` | no |
46+
| subnets | A list of subnets to place the EKS cluster and workers within. | `list(string)` | n/a | yes |
4747
| tags | A map of tags to add to all resources | `map(string)` | n/a | yes |
48+
| vpc\_id | VPC where the cluster and workers will be deployed. | `string` | n/a | yes |
49+
| worker\_additional\_security\_group\_ids | A list of additional security group ids to attach to worker instances | `list(string)` | `[]` | no |
50+
| worker\_ami\_name\_filter | Name filter for AWS EKS worker AMI. If not provided, the latest official AMI for the specified 'cluster\_version' is used. | `string` | `""` | no |
51+
| worker\_ami\_name\_filter\_windows | Name filter for AWS EKS Windows worker AMI. If not provided, the latest official AMI for the specified 'cluster\_version' is used. | `string` | `""` | no |
52+
| worker\_ami\_owner\_id | The ID of the owner for the AMI to use for the AWS EKS workers. Valid values are an AWS account ID, 'self' (the current account), or an AWS owner alias (e.g. 'amazon', 'aws-marketplace', 'microsoft'). | `string` | `"602401143452"` | no |
53+
| worker\_ami\_owner\_id\_windows | The ID of the owner for the AMI to use for the AWS EKS Windows workers. Valid values are an AWS account ID, 'self' (the current account), or an AWS owner alias (e.g. 'amazon', 'aws-marketplace', 'microsoft'). | `string` | `"801119661308"` | no |
4854
| worker\_create\_initial\_lifecycle\_hooks | Whether to create initial lifecycle hooks provided in worker groups. | `bool` | `false` | no |
55+
| worker\_create\_security\_group | Whether to create a security group for the workers or attach the workers to `worker_security_group_id`. | `bool` | `true` | no |
4956
| worker\_groups | A map of maps defining worker group configurations to be defined using AWS Launch Templates. See workers\_group\_defaults for valid keys. | `any` | `{}` | no |
50-
| worker\_security\_group\_ids | A list of security group ids to attach to worker instances. | `list(string)` | `[]` | no |
57+
| 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 ingress/egress to work with the EKS cluster. | `string` | `""` | no |
58+
| 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). | `number` | `1025` | no |
5159
| workers\_group\_defaults | Workers group defaults from parent | `any` | n/a | yes |
5260

5361
## Outputs
@@ -56,5 +64,6 @@ No requirements.
5664
|------|-------------|
5765
| aws\_auth\_roles | Roles for use in aws-auth ConfigMap |
5866
| worker\_groups | Outputs from EKS worker groups. Map of maps, keyed by `var.worker_groups` keys. |
67+
| worker\_security\_group\_id | Security group ID attached to the EKS workers. |
5968

6069
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

modules/worker_groups/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ resource "aws_autoscaling_group" "workers" {
77
[
88
var.cluster_name,
99
each.key,
10-
each.value["asg_recreate_on_change"] ? random_pet.workers[each.key].id : ""
10+
true ? random_pet.workers[each.key].id : "kk"
1111
]
1212
)
1313
)

0 commit comments

Comments
 (0)