UPD: added back spot instance support

This commit is contained in:
xpk 2024-01-30 18:03:09 +08:00
parent 5a9f2e08c6
commit a112747c14
Signed by: xpk
GPG Key ID: CD4FF6793F09AB86
2 changed files with 20 additions and 0 deletions

View File

@ -27,6 +27,21 @@ resource "aws_instance" "ec2-instance" {
} }
} }
# spot instance option
dynamic "instance_market_options" {
for_each = var.spot-max-price > 0 ? { use_spot : true } : {}
content {
market_type = "spot"
dynamic "spot_options" {
for_each = { use_spot : true }
content {
max_price = var.spot-max-price
}
}
}
}
disable_api_termination = var.enable-termination-protection disable_api_termination = var.enable-termination-protection
user_data = var.user-data user_data = var.user-data
monitoring = var.enable-detail-monitoring monitoring = var.enable-detail-monitoring

View File

@ -94,4 +94,9 @@ variable "enable-detail-monitoring" {
type = bool type = bool
default = false default = false
description = "Set true to enable detail monitoring" description = "Set true to enable detail monitoring"
}
variable spot-max-price {
type = number
description = "Max hourly price for spot instance. If greater than zero, spot instance will be used."
default = 0
} }