FEAT: added spot instance support to ec2 module

This commit is contained in:
xpk 2024-01-30 10:07:49 +08:00
parent 1fe92a3f78
commit c2a73ed6fa
Signed by: xpk
GPG Key ID: CD4FF6793F09AB86
3 changed files with 24 additions and 3 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

@ -4,7 +4,7 @@ terraform {
required_providers { required_providers {
aws = { aws = {
source = "hashicorp/aws" source = "hashicorp/aws"
version = "~> 5.0.0" version = "~> 5.34.0"
} }
} }
} }

View File

@ -51,3 +51,9 @@ variable "enable-detail-monitoring" {
type = bool type = bool
default = false default = false
} }
variable spot-max-price {
type = number
default = 0
description = "Specify max price for spot instance."
}