Skip to content

Commit

Permalink
Allow spot instances to be used (#36)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ajbrown authored and tfhartmann committed Sep 20, 2018
1 parent 9c91e91 commit dbe7c16
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.iml
.idea/
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
-----
Expand Down
1 change: 1 addition & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ variable "ebs_block_device" {
}

variable "extra_tags" {
type = "list"
default = []
}

Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit dbe7c16

Please sign in to comment.