Skip to content
This repository was archived by the owner on Jul 20, 2024. It is now read-only.

Commit f8edccd

Browse files
Duy Phamint128
authored andcommitted
Add boolean variable use_spot_instance (#10)
* Add variable use_spot_instance * Set on_demand_base_capacity
1 parent f8b2dc9 commit f8edccd

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

‎README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ This is an open source software. Feel free to open issues and pull requests.
155155
|------|-------------|:----:|:-----:|:-----:|
156156
| extra\_user\_data | Extra script to run in the NAT instance | string | `""` | no |
157157
| image\_id | AMI of the NAT instance. Default to the latest Amazon Linux 2 | string | `""` | no |
158-
| instance\_types | Candidates of spot instance type for the NAT instance. This is used in the mixed instances policy | list | `[ "t3.nano", "t3a.nano" ]` | no |
158+
| instance\_types | Candidates of instance type for the NAT instance. This is used in the mixed instances policy | list | `[ "t3.nano", "t3a.nano" ]` | no |
159+
| use_spot_instance | Whether to use spot or on-demand EC2 instance | boolean | true | no |
159160
| key\_name | Name of the key pair for the NAT instance. You can set this to assign the key pair to the NAT instance | string | `""` | no |
160161
| name | Name for all the resources as identifier | string | n/a | yes |
161162
| private\_route\_table\_ids | List of ID of the route tables for the private subnets. You can set this to assign the each default route to the NAT instance | list | `[]` | no |

‎main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ resource "aws_autoscaling_group" "this" {
112112

113113
mixed_instances_policy {
114114
instances_distribution {
115-
on_demand_percentage_above_base_capacity = 0
115+
on_demand_base_capacity = var.use_spot_instance ? 0 : 1
116+
on_demand_percentage_above_base_capacity = var.use_spot_instance ? 0 : 100
116117
}
117118
launch_template {
118119
launch_template_specification {

‎variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ variable "instance_types" {
3434
default = ["t3.nano", "t3a.nano"]
3535
}
3636

37+
variable "use_spot_instance" {
38+
description = "Whether to use spot or on-demand EC2 instance"
39+
default = true
40+
}
41+
3742
variable "key_name" {
3843
description = "Name of the key pair for the NAT instance. You can set this to assign the key pair to the NAT instance"
3944
default = ""

0 commit comments

Comments
 (0)