Skip to content

Commit dba6b0d

Browse files
jonathan-mothershipArchiFleKs
authored andcommitted
feat: Add the SPOT support for Managed Node Groups (terraform-aws-modules#1129)
BREAKING CHANGES: To add add SPOT support for MNG, the `instance_type` is now a list and renamed as `instance_types`. This will probably rebuild existing Managed Node Groups.
1 parent a7521b5 commit dba6b0d

File tree

5 files changed

+11
-5
lines changed

5 files changed

+11
-5
lines changed

examples/managed_node_groups/main.tf

+2-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ module "eks" {
100100
max_capacity = 10
101101
min_capacity = 1
102102

103-
instance_type = "m5.large"
103+
instance_types = ["m5.large"]
104+
capacity_type = "SPOT"
104105
k8s_labels = {
105106
Environment = "test"
106107
GithubRepo = "terraform-aws-eks"

modules/node_groups/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ The role ARN specified in `var.default_iam_role_arn` will be used by default. In
2020
| additional\_tags | Additional tags to apply to node group | map(string) | Only `var.tags` applied |
2121
| ami\_release\_version | AMI version of workers | string | Provider default behavior |
2222
| ami\_type | AMI Type. See Terraform or AWS docs | string | Provider default behavior |
23+
| capacity\_type | Type of instance capacity to provision. Options are `ON_DEMAND` and `SPOT` | string | Provider default behavior |
2324
| desired\_capacity | Desired number of workers | number | `var.workers_group_defaults[asg_desired_capacity]` |
2425
| disk\_size | Workers' disk size | number | Provider default behavior |
2526
| iam\_role\_arn | IAM role ARN for workers | string | `var.default_iam_role_arn` |
26-
| instance\_type | Workers' instance type | string | `var.workers_group_defaults[instance_type]` |
27+
| instance\_types | Node group's instance type(s). Multiple types can be specified when `capacity_type="SPOT"`. | list | `[var.workers_group_defaults[instance_type]]` |
2728
| k8s\_labels | Kubernetes labels | map(string) | No labels applied |
2829
| key\_name | Key name for workers. Set to empty string to disable remote access | string | `var.workers_group_defaults[key_name]` |
2930
| launch_template_id | The id of a aws_launch_template to use | string | No LT used |

modules/node_groups/locals.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ locals {
44
{
55
desired_capacity = var.workers_group_defaults["asg_desired_capacity"]
66
iam_role_arn = var.default_iam_role_arn
7-
instance_type = var.workers_group_defaults["instance_type"]
7+
instance_types = [var.workers_group_defaults["instance_type"]]
88
key_name = var.workers_group_defaults["key_name"]
99
launch_template_id = var.workers_group_defaults["launch_template_id"]
1010
launch_template_version = var.workers_group_defaults["launch_template_version"]

modules/node_groups/node_groups.tf

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ resource "aws_eks_node_group" "workers" {
1515

1616
ami_type = lookup(each.value, "ami_type", null)
1717
disk_size = lookup(each.value, "disk_size", null)
18-
instance_types = each.value["launch_template_id"] != null ? [] : [each.value["instance_type"]]
18+
instance_types = lookup(each.value, "instance_types", null)
1919
release_version = lookup(each.value, "ami_release_version", null)
20+
capacity_type = lookup(each.value, "capacity_type", null)
2021

2122
dynamic "remote_access" {
2223
for_each = each.value["key_name"] != "" ? [{

modules/node_groups/random.tf

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ resource "random_pet" "node_groups" {
77
keepers = {
88
ami_type = lookup(each.value, "ami_type", null)
99
disk_size = lookup(each.value, "disk_size", null)
10-
instance_type = each.value["instance_type"]
10+
capacity_type = lookup(each.value, "capacity_type", null)
1111
iam_role_arn = each.value["iam_role_arn"]
12+
instance_types = join("|", compact(
13+
lookup(each.value, "instance_types", [])
14+
))
1215

1316
key_name = each.value["key_name"]
1417

0 commit comments

Comments
 (0)