From dbe7c16267604310b1075c1e705cd04e95e13267 Mon Sep 17 00:00:00 2001 From: "A.J. Brown" Date: Thu, 20 Sep 2018 13:16:45 -0400 Subject: [PATCH] Allow spot instances to be used (#36) * Allow spot instances to be used An optional variable `spot_bid_price` has been added, which will allow spot instances to be used for the ECS cluster. When not specified (the default), standard on-demand instances will still be used. * Formatted files --- .gitignore | 2 ++ README.md | 4 +++- main.tf | 1 + variables.tf | 6 ++++++ 4 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0cc2124 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.iml +.idea/ diff --git a/README.md b/README.md index d4a971e..1f837c1 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ extra_tags = [ - `allowed_cidr_blocks` - List of subnets to allow into the ECS Security Group. Defaults to `["0.0.0.0/0"]`. - `ami` - A specific AMI image to use, eg `ami-95f8d2f3`. Defaults to the latest ECS optimized Amazon Linux AMI. - `ami_version` - Specific version of the Amazon ECS AMI to use (e.g. `2016.09`). Defaults to `*`. Ignored if `ami` is specified. -- `heartbeat_timeout` - Heartbeat Timeout setting for how long it takes for the graceful shutodwn hook takes to timeout. This is useful when deploying clustered applications like consul that benifit from having a deploy between autoscaling create/destroy actions. Defaults to 180" +- `heartbeat_timeout` - Heartbeat Timeout setting for how long it takes for the graceful shutdown hook takes to timeout. This is useful when deploying clustered applications like consul that benifit from having a deploy between autoscaling create/destroy actions. Defaults to 180" - `security_group_ids` - a list of security group IDs to apply to the launch configuration - `user_data` - The instance user data (e.g. a `cloud-init` config) to use in the `aws_launch_configuration` - custom_iam_policy - JSON containing the custom IAM policy for ECS nodes. Will overwrite the default one if set. @@ -56,6 +56,8 @@ extra_tags = [ - `consul_memory_reservation` - The soft limit (in MiB) of memory to reserve for the container, defaults 20 - `registrator_memory_reservation` - The soft limit (in MiB) of memory to reserve for the container, defaults 20 - `enable_agents` - Enable Consul Agent and Registrator tasks on each ECS Instance. Defaults to false +- `spot_bid_price` - Use spot instances and request this bid price. Note that with this option you risk your instances + shutting down if the market price rises above your bid price. Usage ----- diff --git a/main.tf b/main.tf index 99f1d01..47b5ba9 100644 --- a/main.tf +++ b/main.tf @@ -36,6 +36,7 @@ resource "aws_launch_configuration" "ecs" { iam_instance_profile = "${aws_iam_instance_profile.ecs_profile.name}" security_groups = ["${concat(list(aws_security_group.ecs.id), var.security_group_ids)}"] associate_public_ip_address = "${var.associate_public_ip_address}" + spot_price = "${var.spot_bid_price}" ebs_block_device { device_name = "${var.ebs_block_device}" diff --git a/variables.tf b/variables.tf index 9a12015..f35fa78 100644 --- a/variables.tf +++ b/variables.tf @@ -56,6 +56,7 @@ variable "ebs_block_device" { } variable "extra_tags" { + type = "list" default = [] } @@ -127,6 +128,11 @@ variable "servers" { description = "The number of servers to launch." } +variable "spot_bid_price" { + default = "" + description = "If specified, spot instances will be requested at this bid price. If not specified, on-demand instances will be used." +} + variable "subnet_id" { type = "list" description = "The AWS Subnet ID in which you want to delpoy your instances"