Skip to content

Commit ada4275

Browse files
authored
enhancement: Bumped upstream version of eks module and changed variables to support better handling of node group changes, also added missing provider requirements. (#52)
* enhancement: Bumped upstream version of eks module and changed variables to support better handling of node group changes, also added missing provider requirements. BREAKING CHANGE: The change to the EKS module had its own breaking change that will require a bit of state management, you can read about it here: https://github.com/terraform-aws-modules/terraform-aws-eks/blob/master/docs/upgrades.md#upgrade-module-to-v1700-for-managed-node-groups . Also, this change may require some state management since it changes the name of the node group. You should be able to upgrade gracefully by importing the previous group into the state and removing the old one. Feel free to ask in the community channel at slack.getzero.dev if you have any questions. * fix: Bump validation workflow to tf 1.0
1 parent f45c826 commit ada4275

File tree

8 files changed

+54
-60
lines changed

8 files changed

+54
-60
lines changed

.chglog/config.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ options:
1616
- test
1717
- ci
1818
- breaking
19-
commit_groups:
20-
# title_maps:
21-
# feat: Features
22-
# fix: Bug Fixes
23-
# perf: Performance Improvements
24-
# refactor: Code Refactoring
2519
commit_groups:
2620
group_by: Type
2721
sort_by: Type

.github/workflows/terraform.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- uses: actions/checkout@v2
1515
- uses: hashicorp/setup-terraform@v1
1616
with:
17-
terraform_version: 0.14.8 # Required as of Apr 15 2021 because of breaking changes in tf 0.15
17+
terraform_version: 1.0.1 # Required as of Apr 15 2021 because of breaking changes in tf 0.15
1818

1919
- name: Terraform fmt
2020
id: fmt

modules/certificate/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ This module requires an aws provider in the **us-east-1** region to be passed in
1212
| Name | Version |
1313
|------|---------|
1414
| terraform | >= 0.13 |
15+
| aws | >= 3.37.0 |
1516

1617
## Providers
1718

1819
| Name | Version |
1920
|------|---------|
20-
| aws | n/a |
21+
| aws | >= 3.37.0 |
2122

2223
## Inputs
2324

modules/certificate/versions.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11

22
terraform {
33
required_version = ">= 0.13"
4+
5+
required_providers {
6+
aws = {
7+
source = "hashicorp/aws"
8+
version = ">= 3.37.0"
9+
}
10+
}
411
}

modules/eks/README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,27 @@ Create a Kubernetes cluster using EKS.
1010
| Name | Version |
1111
|------|---------|
1212
| terraform | >= 0.13 |
13+
| aws | >= 3.37.0 |
1314

1415
## Providers
1516

1617
| Name | Version |
1718
|------|---------|
18-
| aws | n/a |
19+
| aws | >= 3.37.0 |
1920

2021
## Inputs
2122

2223
| Name | Description | Type | Default | Required |
2324
|------|-------------|------|---------|:--------:|
2425
| cluster\_name | Name to be given to the EKS cluster | `any` | n/a | yes |
2526
| cluster\_version | EKS cluster version number to use. Incrementing this will start a cluster upgrade | `any` | n/a | yes |
27+
| eks\_node\_groups | Map of maps of EKS node group config where keys are node group names | <pre>map(object({<br> instance_types = list(string)<br> asg_min_size = string<br> asg_max_size = string<br> use_spot_instances = bool<br> ami_type = string<br> }))</pre> | n/a | yes |
2628
| environment | The environment (stage/prod) | `any` | n/a | yes |
2729
| iam\_account\_id | Account ID of the current IAM user | `any` | n/a | yes |
2830
| iam\_role\_mapping | List of mappings of AWS Roles to Kubernetes Groups | <pre>list(object({<br> iam_role_arn = string<br> k8s_role_name = string<br> k8s_groups = list(string)<br> }))</pre> | n/a | yes |
2931
| private\_subnets | VPC subnets for the EKS cluster | `list(string)` | n/a | yes |
3032
| project | Name of the project | `any` | n/a | yes |
31-
| use\_spot\_instances | Enable use of spot instances instead of on-demand. This can provide significant cost savings and should be stable due to the use of the termination handler, but means that individuial nodes could be restarted at any time. May not be suitable for clusters with long-running workloads | `bool` | `false` | no |
3233
| vpc\_id | VPC ID for EKS cluster | `any` | n/a | yes |
33-
| worker\_ami\_type | AMI type for the EKS worker instances. The default will be the normal image. Other possibilities are AL2\_x86\_64\_GPU for gpu instances or AL2\_ARM\_64 for ARM instances | `string` | `"AL2_x86_64"` | no |
34-
| worker\_asg\_max\_size | Maximum number of instances for the EKS ASG | `any` | n/a | yes |
35-
| worker\_asg\_min\_size | Minimum number of instances for the EKS ASG | `any` | n/a | yes |
36-
| worker\_instance\_types | Instance types to use for the EKS workers. When use\_spot\_instances is true you may provide multiple instance types and it will diversify across the cheapest pools | `list(string)` | `[]` | no |
3734

3835
## Outputs
3936

modules/eks/main.tf

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,21 @@ data "aws_eks_cluster_auth" "cluster" {
77
name = module.eks.cluster_id
88
}
99

10-
module "eks" {
11-
source = "terraform-aws-modules/eks/aws"
12-
version = "16.1.0"
13-
14-
cluster_name = var.cluster_name
15-
cluster_version = var.cluster_version
16-
subnets = var.private_subnets
17-
vpc_id = var.vpc_id
18-
enable_irsa = true
19-
20-
21-
node_groups_defaults = {
22-
ami_type = var.worker_ami_type
23-
disk_size = 100
24-
}
10+
locals {
11+
# Map this module config to the upstream module config
12+
eks_node_group_config = { for n, config in var.eks_node_groups :
13+
n => {
14+
name = "${var.cluster_name}-${n}"
2515

26-
node_groups = {
27-
cluster = {
28-
name = "${var.cluster_name}-eks"
16+
desired_capacity = config.asg_min_size
17+
max_capacity = config.asg_max_size
18+
min_capacity = config.asg_min_size
2919

30-
desired_capacity = var.worker_asg_min_size
31-
max_capacity = var.worker_asg_max_size
32-
min_capacity = var.worker_asg_min_size
20+
ami_type = config.ami_type
21+
instance_types = config.instance_types
22+
capacity_type = config.use_spot_instances ? "SPOT" : "ON_DEMAND"
23+
disk_size = 100
3324

34-
instance_types = var.worker_instance_types
35-
capacity_type = var.use_spot_instances ? "SPOT" : "ON_DEMAND"
3625
k8s_labels = {
3726
Environment = var.environment
3827
}
@@ -41,6 +30,19 @@ module "eks" {
4130
}
4231
}
4332
}
33+
}
34+
35+
module "eks" {
36+
source = "terraform-aws-modules/eks/aws"
37+
version = "17.1.0"
38+
39+
cluster_name = var.cluster_name
40+
cluster_version = var.cluster_version
41+
subnets = var.private_subnets
42+
vpc_id = var.vpc_id
43+
enable_irsa = true
44+
45+
node_groups = local.eks_node_group_config
4446

4547
map_roles = concat(
4648
[{

modules/eks/variables.tf

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,15 @@ variable "vpc_id" {
2323
description = "VPC ID for EKS cluster"
2424
}
2525

26-
variable "worker_instance_types" {
27-
description = "Instance types to use for the EKS workers. When use_spot_instances is true you may provide multiple instance types and it will diversify across the cheapest pools"
28-
type = list(string)
29-
default = []
30-
}
31-
32-
variable "worker_ami_type" {
33-
description = "AMI type for the EKS worker instances. The default will be the normal image. Other possibilities are AL2_x86_64_GPU for gpu instances or AL2_ARM_64 for ARM instances"
34-
type = string
35-
default = "AL2_x86_64"
36-
}
37-
variable "use_spot_instances" {
38-
description = "Enable use of spot instances instead of on-demand. This can provide significant cost savings and should be stable due to the use of the termination handler, but means that individuial nodes could be restarted at any time. May not be suitable for clusters with long-running workloads"
39-
type = bool
40-
default = false
41-
}
42-
43-
variable "worker_asg_min_size" {
44-
description = "Minimum number of instances for the EKS ASG"
45-
}
46-
47-
variable "worker_asg_max_size" {
48-
description = "Maximum number of instances for the EKS ASG"
26+
variable "eks_node_groups" {
27+
type = map(object({
28+
instance_types = list(string)
29+
asg_min_size = string
30+
asg_max_size = string
31+
use_spot_instances = bool
32+
ami_type = string
33+
}))
34+
description = "Map of maps of EKS node group config where keys are node group names"
4935
}
5036

5137
variable "iam_account_id" {

modules/eks/versions.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11

22
terraform {
33
required_version = ">= 0.13"
4+
5+
required_providers {
6+
aws = {
7+
source = "hashicorp/aws"
8+
version = ">= 3.37.0"
9+
}
10+
}
411
}

0 commit comments

Comments
 (0)