FEAT: added spot instance support to ec2 module
This commit is contained in:
parent
1fe92a3f78
commit
c2a73ed6fa
@ -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)
|
||||
|
@ -4,7 +4,7 @@ terraform {
|
||||
required_providers {
|
||||
aws = {
|
||||
source = "hashicorp/aws"
|
||||
version = "~> 5.0.0"
|
||||
version = "~> 5.34.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,4 +50,10 @@ variable "user-data" {
|
||||
variable "enable-detail-monitoring" {
|
||||
type = bool
|
||||
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