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,9 +27,24 @@ 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
user_data = var.user-data
monitoring = var.enable-detail-monitoring
user_data = var.user-data
monitoring = var.enable-detail-monitoring
tags = merge(var.additional-tags, { "Name" : var.instance-name })
volume_tags = merge({ "Name" : var.instance-name }, data.aws_default_tags.this.tags)

View File

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

View File

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