Files
opentf/website/source/docs/providers/aws/r/spot_instance_request.html.markdown
Paul Hinze 112724fc39 provider/aws: spot_instance_request
This is an iteration on the great work done by @dalehamel in PRs #2095
and #2109.

The core team went back and forth on how to best model Spot Instance
Requests, requesting and then rejecting a separate-resource
implementation in #2109.

After more internal discussion, we landed once again on a separate
resource to model Spot Instance Requests. Out of respect for
@dalehamel's already-significant donated time, with this I'm attempting
to pick up the work to take this across the finish line.

Important architectural decisions represented here:

 * Spot Instance Requests are always of type "persistent", to properly
   match Terraform's declarative model.
 * The spot_instance_request resource exports several attributes that
   are expected to be constantly changing as the spot market changes:
   spot_bid_status, spot_request_state, and instance_id. Creating
   additional resource dependencies based on these attributes is not
   recommended, as Terraform diffs will be continually generated to keep
   up with the live changes.
 * When a Spot Instance Request is deleted/canceled, an attempt is made
   to terminate the last-known attached spot instance. Race conditions
   dictate that this attempt cannot guarantee that the associated spot
   instance is terminated immediately.

Implementation notes:

 * This version of aws_spot_instance_request borrows a lot of common
   code from aws_instance.
 * In order to facilitate borrowing, we introduce `awsInstanceOpts`, an
   internal representation of instance details that's meant to be shared
   between resources. The goal here would be to refactor ASG Launch
   Configurations to use the same struct.
 * The new aws_spot_instance_request acc. test is passing.
 * All aws_instance acc. tests remain passing.
2015-06-07 17:33:32 -05:00

2.4 KiB

layout, page_title, sidebar_current, description
layout page_title sidebar_current description
aws AWS: aws_spot_instance_request docs-aws-resource-spot-instance-request Provides a Spot Instance Request resource.

aws_spot_instance_request

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

Terraform always 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.

~> NOTE: Because their behavior depends on the live status of the spot market, Spot Instance Requests have a unique lifecycle that makes them behave differently than other Terraform resources. Most importantly: there is no guarantee that a Spot Instance exists to fulfill the request at any given point in time. See the AWS Spot Instance documentation for more information.

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:

  • spot_price - (Required) The price to request on the spot market.
  • wait_for_fulfillment - (Optional; Default: false) If set, Terraform will wait for the Spot Request to be fulfilled, and will throw an error if the timeout of 10m is reached.

Attributes Reference

The following attributes are exported:

  • id - The Spot Instance Request ID.

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:

  • spot_bid_status - The current bid status of the Spot Instance Request.
  • spot_request_state The current request state of the Spot Instance Request.
  • spot_instance_id - The Instance ID (if any) that is currently fulfilling the Spot Instance request.