Skip to content

Commit

Permalink
Make spot instance resource timeout configurable with wait_for_ready_…
Browse files Browse the repository at this point in the history
…timeout hashicorp#8164
  • Loading branch information
jbarrick-mesosphere committed Apr 3, 2019
1 parent 4bdbd11 commit 675ffcc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 13 additions & 1 deletion aws/resource_aws_spot_instance_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ func resourceAwsSpotInstanceRequest() *schema.Resource {
ValidateFunc: validation.ValidateRFC3339TimeString,
Computed: true,
}
s["wait_for_ready_timeout"] = &schema.Schema{
Type: schema.TypeString,
Optional: true,
Default: "1m",
ValidateFunc: validateDuration,
}

return s
}(),
}
Expand Down Expand Up @@ -172,11 +179,16 @@ func resourceAwsSpotInstanceRequestCreate(d *schema.ResourceData, meta interface
spotOpts.LaunchSpecification.Placement = instanceOpts.SpotPlacement
}

waitForReadyTimeOut, err := time.ParseDuration(d.Get("wait_for_ready_timeout").(string))
if err != nil {
return err
}

// Make the spot instance request
log.Printf("[DEBUG] Requesting spot bid opts: %s", spotOpts)

var resp *ec2.RequestSpotInstancesOutput
err = resource.Retry(1*time.Minute, func() *resource.RetryError {
err = resource.Retry(waitForReadyTimeOut, func() *resource.RetryError {
var err error
resp, err = conn.RequestSpotInstances(spotOpts)
// IAM instance profiles can take ~10 seconds to propagate in AWS:
Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/spot_instance_request.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ Spot Instance Requests support all the same arguments as
* `valid_until` - (Optional) The end date and time of the request, in UTC [RFC3339](https://tools.ietf.org/html/rfc3339#section-5.8) format(for example, YYYY-MM-DDTHH:MM:SSZ). At this point, no new Spot instance requests are placed or enabled to fulfill the request. The default end date is 7 days from the current date.
* `valid_from` - (Optional) The start date and time of the request, in UTC [RFC3339](https://tools.ietf.org/html/rfc3339#section-5.8) format(for example, YYYY-MM-DDTHH:MM:SSZ). The default is to start fulfilling the request immediately.
* `tags` - (Optional) A mapping of tags to assign to the resource.
* `wait_for_ready_timeout` - (Default: `1m`) The maximum
[duration](https://golang.org/pkg/time/#ParseDuration) that Terraform should
wait for the spot instance to be in a ready state before timing out.

### Timeouts

Expand Down

0 comments on commit 675ffcc

Please sign in to comment.