FEAT: added spot instance support to ec2 module
This commit is contained in:
parent
1fe92a3f78
commit
c2a73ed6fa
@ -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
|
||||||
|
@ -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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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."
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user