Skip to content

Commit a9bda0e

Browse files
tbilouactions-botmaximmi
authored
Add support for spot instances (#115)
* Add support for spot instances * Updated README.md * Executed 'terraform fmt' Co-authored-by: tiago bilou <tiago.bilou@xing.com> Co-authored-by: actions-bot <58130806+actions-bot@users.noreply.github.com> Co-authored-by: Maxim Mironenko <maxim@cloudposse.com>
1 parent 7ed1146 commit a9bda0e

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ Available targets:
222222
| elastic_beanstalk_application_name | Elastic Beanstalk application name | string | - | yes |
223223
| elb_scheme | Specify `internal` if you want to create an internal load balancer in your Amazon VPC so that your Elastic Beanstalk application cannot be accessed from outside your Amazon VPC | string | `public` | no |
224224
| enable_log_publication_control | Copy the log files for your application's Amazon EC2 instances to the Amazon S3 bucket associated with your application | bool | `false` | no |
225+
| enable_spot_instances | Enable Spot Instance requests for your environment | bool | `false` | no |
225226
| enable_stream_logs | Whether to create groups in CloudWatch Logs for proxy and deployment logs, and stream logs from each instance in your environment | bool | `false` | no |
226227
| enhanced_reporting_enabled | Whether to enable "enhanced" health reporting for this environment. If false, "basic" reporting is used. When you set this to false, you must also set `enable_managed_actions` to false | bool | `true` | no |
227228
| env_vars | Map of custom ENV variables to be provided to the application running on Elastic Beanstalk, e.g. env_vars = { DB_USER = 'admin' DB_PASS = 'xxxxxx' } | map(string) | `<map>` | no |
@@ -254,6 +255,9 @@ Available targets:
254255
| root_volume_size | The size of the EBS root volume | number | `8` | no |
255256
| root_volume_type | The type of the EBS root volume | string | `gp2` | no |
256257
| solution_stack_name | Elastic Beanstalk stack, e.g. Docker, Go, Node, Java, IIS. For more info, see https://docs.aws.amazon.com/elasticbeanstalk/latest/platforms/platforms-supported.html | string | - | yes |
258+
| spot_fleet_on_demand_above_base_percentage | The percentage of On-Demand Instances as part of additional capacity that your Auto Scaling group provisions beyond the SpotOnDemandBase instances. This option is relevant only when enable_spot_instances is true. | number | `-1` | no |
259+
| spot_fleet_on_demand_base | The minimum number of On-Demand Instances that your Auto Scaling group provisions before considering Spot Instances as your environment scales up. This option is relevant only when enable_spot_instances is true. | number | `0` | no |
260+
| spot_max_price | The maximum price per unit hour, in US$, that you're willing to pay for a Spot Instance. This option is relevant only when enable_spot_instances is true. Valid values are between 0.001 and 20.0 | number | `-1` | no |
257261
| ssh_listener_enabled | Enable SSH port | bool | `false` | no |
258262
| ssh_listener_port | SSH port | number | `22` | no |
259263
| ssh_source_restriction | Used to lock down SSH access to the EC2 instances | string | `0.0.0.0/0` | no |

docs/terraform.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
| elastic_beanstalk_application_name | Elastic Beanstalk application name | string | - | yes |
2828
| elb_scheme | Specify `internal` if you want to create an internal load balancer in your Amazon VPC so that your Elastic Beanstalk application cannot be accessed from outside your Amazon VPC | string | `public` | no |
2929
| enable_log_publication_control | Copy the log files for your application's Amazon EC2 instances to the Amazon S3 bucket associated with your application | bool | `false` | no |
30+
| enable_spot_instances | Enable Spot Instance requests for your environment | bool | `false` | no |
3031
| enable_stream_logs | Whether to create groups in CloudWatch Logs for proxy and deployment logs, and stream logs from each instance in your environment | bool | `false` | no |
3132
| enhanced_reporting_enabled | Whether to enable "enhanced" health reporting for this environment. If false, "basic" reporting is used. When you set this to false, you must also set `enable_managed_actions` to false | bool | `true` | no |
3233
| env_vars | Map of custom ENV variables to be provided to the application running on Elastic Beanstalk, e.g. env_vars = { DB_USER = 'admin' DB_PASS = 'xxxxxx' } | map(string) | `<map>` | no |
@@ -59,6 +60,9 @@
5960
| root_volume_size | The size of the EBS root volume | number | `8` | no |
6061
| root_volume_type | The type of the EBS root volume | string | `gp2` | no |
6162
| solution_stack_name | Elastic Beanstalk stack, e.g. Docker, Go, Node, Java, IIS. For more info, see https://docs.aws.amazon.com/elasticbeanstalk/latest/platforms/platforms-supported.html | string | - | yes |
63+
| spot_fleet_on_demand_above_base_percentage | The percentage of On-Demand Instances as part of additional capacity that your Auto Scaling group provisions beyond the SpotOnDemandBase instances. This option is relevant only when enable_spot_instances is true. | number | `-1` | no |
64+
| spot_fleet_on_demand_base | The minimum number of On-Demand Instances that your Auto Scaling group provisions before considering Spot Instances as your environment scales up. This option is relevant only when enable_spot_instances is true. | number | `0` | no |
65+
| spot_max_price | The maximum price per unit hour, in US$, that you're willing to pay for a Spot Instance. This option is relevant only when enable_spot_instances is true. Valid values are between 0.001 and 20.0 | number | `-1` | no |
6266
| ssh_listener_enabled | Enable SSH port | bool | `false` | no |
6367
| ssh_listener_port | SSH port | number | `22` | no |
6468
| ssh_source_restriction | Used to lock down SSH access to the EC2 instances | string | `0.0.0.0/0` | no |

main.tf

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,11 +623,35 @@ resource "aws_elastic_beanstalk_environment" "default" {
623623
}
624624

625625
setting {
626-
namespace = "aws:autoscaling:launchconfiguration"
627-
name = "InstanceType"
626+
namespace = "aws:ec2:instances"
627+
name = "InstanceTypes"
628628
value = var.instance_type
629629
}
630630

631+
setting {
632+
namespace = "aws:ec2:instances"
633+
name = "EnableSpot"
634+
value = var.enable_spot_instances ? "true" : "false"
635+
}
636+
637+
setting {
638+
namespace = "aws:ec2:instances"
639+
name = "SpotFleetOnDemandBase"
640+
value = var.spot_fleet_on_demand_base
641+
}
642+
643+
setting {
644+
namespace = "aws:ec2:instances"
645+
name = "SpotFleetOnDemandAboveBasePercentage"
646+
value = var.spot_fleet_on_demand_above_base_percentage == -1 ? (var.environment_type == "LoadBalanced" ? 70 : 0) : var.spot_fleet_on_demand_above_base_percentage
647+
}
648+
649+
setting {
650+
namespace = "aws:ec2:instances"
651+
name = "SpotMaxPrice"
652+
value = var.spot_max_price == -1 ? "null" : var.spot_max_price
653+
}
654+
631655
setting {
632656
namespace = "aws:autoscaling:launchconfiguration"
633657
name = "EC2KeyName"

variables.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,30 @@ variable "instance_type" {
119119
description = "Instances type"
120120
}
121121

122+
variable "enable_spot_instances" {
123+
type = bool
124+
default = false
125+
description = "Enable Spot Instance requests for your environment"
126+
}
127+
128+
variable "spot_fleet_on_demand_base" {
129+
type = number
130+
default = 0
131+
description = "The minimum number of On-Demand Instances that your Auto Scaling group provisions before considering Spot Instances as your environment scales up. This option is relevant only when enable_spot_instances is true."
132+
}
133+
134+
variable "spot_fleet_on_demand_above_base_percentage" {
135+
type = number
136+
default = -1
137+
description = "The percentage of On-Demand Instances as part of additional capacity that your Auto Scaling group provisions beyond the SpotOnDemandBase instances. This option is relevant only when enable_spot_instances is true."
138+
}
139+
140+
variable "spot_max_price" {
141+
type = number
142+
default = -1
143+
description = "The maximum price per unit hour, in US$, that you're willing to pay for a Spot Instance. This option is relevant only when enable_spot_instances is true. Valid values are between 0.001 and 20.0"
144+
}
145+
122146
variable "enhanced_reporting_enabled" {
123147
type = bool
124148
default = true

0 commit comments

Comments
 (0)