From a95ad00b0a9a0ca5e519dab5b07bcd6d827aec6a Mon Sep 17 00:00:00 2001 From: Onur Sam <51121022+onur-sam-gtn-ai@users.noreply.github.com> Date: Tue, 23 Jul 2019 16:33:16 +0100 Subject: [PATCH] added market options to request spot instances without pools (#409) * added market options to request spot instances without specifying pools in a launch template * formatted * simplified implementation * formatted * Update CHANGELOG.md --- CHANGELOG.md | 1 + local.tf | 1 + workers_launch_template.tf | 8 ++++++++ 3 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03cd0a1..ad9eb3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ project adheres to [Semantic Versioning](http://semver.org/). - Option to set a KMS key for the log group and encrypt it (by @till-krauss) - Output the name of the cloudwatch log group (by @gbooth27) + - Option to use spot instances with launch templates without defining pools, especially useful for GPU instance types (@onur-sam-gtn-ai) - Added `cpu_credits` param for the workers defined in `worker_groups_launch_template` (by @a-shink) - Write your awesome addition here (by @you) diff --git a/local.tf b/local.tf index 8cf58fd..e2f8b3a 100644 --- a/local.tf +++ b/local.tf @@ -81,6 +81,7 @@ locals { spot_allocation_strategy = "lowest-price" # The only valid value is lowest-price, which is also the default value. The Auto Scaling group selects the cheapest Spot pools and evenly allocates your Spot capacity across the number of Spot pools that you specify. spot_instance_pools = 10 # "Number of Spot pools per availability zone to allocate capacity. EC2 Auto Scaling selects the cheapest Spot pools and evenly allocates Spot capacity across the number of Spot pools that you specify." spot_max_price = "" # Maximum price per unit hour that the user is willing to pay for the Spot instances. Default is the on-demand price + market_type = null # set to "spot" to use spot instances without defining pools } workers_group_defaults = merge( diff --git a/workers_launch_template.tf b/workers_launch_template.tf index b57f4e6..caee563 100644 --- a/workers_launch_template.tf +++ b/workers_launch_template.tf @@ -229,6 +229,14 @@ resource "aws_launch_template" "workers_launch_template" { ) } + instance_market_options { + market_type = lookup( + var.worker_groups_launch_template[count.index], + "market_type", + local.workers_group_defaults["market_type"], + ) + } + block_device_mappings { device_name = lookup( var.worker_groups_launch_template[count.index],