Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for spot instances node groups. #1161

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions examples/launch_templates_with_managed_node_groups/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,18 @@ module "eks" {
CustomTag = "EKS example"
}
}

spot-example = {
name = "spot-example"
desired_capacity = 1
max_capacity = 20
min_capacity = 1
instance_type = ["m5.large", "m5a.large", "m5d.large", "m5ad.large"]
capacity_type = "SPOT"
k8s_labels = {
lifecycle = "spot"
node-type = "microservice"
}
}
}
}
3 changes: 2 additions & 1 deletion modules/node_groups/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ The role ARN specified in `var.default_iam_role_arn` will be used by default. In
| additional\_tags | Additional tags to apply to node group | map(string) | Only `var.tags` applied |
| ami\_release\_version | AMI version of workers | string | Provider default behavior |
| ami\_type | AMI Type. See Terraform or AWS docs | string | Provider default behavior |
| capacity_type | Type of nodes in the nodegroup (ON_DEMAND or SPOT) | string | Provider default behavior (ON_DEMAND) |
| desired\_capacity | Desired number of workers | number | `var.workers_group_defaults[asg_desired_capacity]` |
| disk\_size | Workers' disk size | number | Provider default behavior |
| iam\_role\_arn | IAM role ARN for workers | string | `var.default_iam_role_arn` |
| instance\_type | Workers' instance type | string | `var.workers_group_defaults[instance_type]` |
| instance\_type | Workers' instance type | string or list(string) | `var.workers_group_defaults[instance_type]` |
| k8s\_labels | Kubernetes labels | map(string) | No labels applied |
| key\_name | Key name for workers. Set to empty string to disable remote access | string | `var.workers_group_defaults[key_name]` |
| launch_template_id | The id of a aws_launch_template to use | string | No LT used |
Expand Down
3 changes: 2 additions & 1 deletion modules/node_groups/node_groups.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ resource "aws_eks_node_group" "workers" {

ami_type = lookup(each.value, "ami_type", null)
disk_size = lookup(each.value, "disk_size", null)
instance_types = each.value["launch_template_id"] != null ? [] : [each.value["instance_type"]]
instance_types = each.value["launch_template_id"] != null ? [] : flatten([each.value["instance_type"]])
release_version = lookup(each.value, "ami_release_version", null)
capacity_type = lookup(each.value, "capacity_type", "ON_DEMAND")

dynamic "remote_access" {
for_each = each.value["key_name"] != "" ? [{
Expand Down
2 changes: 1 addition & 1 deletion modules/node_groups/random.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ resource "random_pet" "node_groups" {
keepers = {
ami_type = lookup(each.value, "ami_type", null)
disk_size = lookup(each.value, "disk_size", null)
instance_type = each.value["instance_type"]
instance_type = join("|", flatten([each.value["instance_type"]]))
iam_role_arn = each.value["iam_role_arn"]

key_name = each.value["key_name"]
Expand Down