Resource: aws_spot_instance_request

Provides an EC2 Spot Instance Request resource. This allows instances to be requested on the spot market.

By default Terraform creates Spot Instance Requests with a persistent type, which means that for the duration of their lifetime, AWS will launch an instance with the configured details if and when the spot market will accept the requested price.

On destruction, Terraform will make an attempt to terminate the associated Spot Instance if there is one present.

Spot Instances requests with a one-time type will close the spot request when the instance is terminated either by the request being below the current spot price availability or by a user.

Example Usage

# Request a spot instance at $0.03
resource "aws_spot_instance_request" "cheap_worker" {
  ami           = "ami-1234"
  spot_price    = "0.03"
  instance_type = "c4.xlarge"

  tags = {
    Name = "CheapWorker"
  }
}

Argument Reference

Spot Instance Requests support all the same arguments as aws_instance, with the addition of:

Attribute Reference

This resource exports the following attributes in addition to the arguments above:

These attributes are exported, but they are expected to change over time and so should only be used for informational purposes, not for resource dependencies:

Timeouts

Configuration options: