From fb71eaf6ff2ae8599c5e0b64bff5f831183abeb3 Mon Sep 17 00:00:00 2001 From: Tarek Abdel Sater Date: Tue, 6 Aug 2019 19:18:06 +0300 Subject: [PATCH] Allow launch template spot instances without mixed policy (#463) * Add option to enable spot without MixedInstancePolicy * Update docs --- CHANGELOG.md | 1 + docs/spot-instances.md | 12 ++++++++++++ local.tf | 1 + workers_launch_template.tf | 8 ++++++++ 4 files changed, 22 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 332fa94b82..7412f84011 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ project adheres to [Semantic Versioning](http://semver.org/). ### Added + - Added `market_type` to `workers_launch_template.tf` allow the usage of spot nodegroups without mixed instances policy. - Added support for log group tag in `./cluster.tf` (@lucas-giaco) - Added support for workers iam role tag in `./workers.tf` (@lucas-giaco) - Write your awesome addition here (by @you) diff --git a/docs/spot-instances.md b/docs/spot-instances.md index ef9df35bc6..33bd807ff1 100644 --- a/docs/spot-instances.md +++ b/docs/spot-instances.md @@ -84,6 +84,18 @@ Launch Template support is a recent addition to both AWS and this module. It mig kubelet_extra_args = "--node-labels=kubernetes.io/lifecycle=spot" } ] + + worker_groups_launch_template = [ + { + name = "spot-2" + instance_type = "m4.xlarge" + asg_max_size = 5 + asg_desired_size = 5 + autoscaling_enabled = true + kubelet_extra_args = "--node-labels=kubernetes.io/lifecycle=spot" + market_type = "spot" + } + ] ``` ## Important issues diff --git a/local.tf b/local.tf index 07c3504b4a..ee1591bce6 100644 --- a/local.tf +++ b/local.tf @@ -56,6 +56,7 @@ locals { root_encrypted = "" # Whether the volume should be encrypted or not eni_delete = true # Delete the ENI on termination (if set to false you will have to manually delete before destroying) cpu_credits = "standard" # T2/T3 unlimited mode, can be 'standard' or 'unlimited'. Used 'standard' mode as default to avoid paying higher costs + market_type = null # Settings for launch templates with mixed instances policy override_instance_types = ["m5.large", "m5a.large", "m5d.large", "m5ad.large"] # A list of override instance types for mixed instances policy on_demand_allocation_strategy = "prioritized" # Strategy to use when launching on-demand instances. Valid values: prioritized. diff --git a/workers_launch_template.tf b/workers_launch_template.tf index 44bcd212c2..df4a231dd7 100644 --- a/workers_launch_template.tf +++ b/workers_launch_template.tf @@ -229,6 +229,14 @@ resource "aws_launch_template" "workers_launch_template" { ) } + dynamic instance_market_options { + iterator = item + for_each = lookup(var.worker_groups_launch_template[count.index], "market_type", null) == null ? [] : list(lookup(var.worker_groups_launch_template[count.index], "market_type", null)) + content { + market_type = item.value + } + } + block_device_mappings { device_name = lookup( var.worker_groups_launch_template[count.index],