Skip to content

Commit

Permalink
Merge pull request #1735 from stack72/f-aws-spot-instance-instance-in…
Browse files Browse the repository at this point in the history
…teruption-1719

resource/aws_spot_instance_request: Add support for instance_interruption_behaviour
  • Loading branch information
radeksimko authored Sep 27, 2017
2 parents f7deedd + 5d6ba9d commit f677c37
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
9 changes: 8 additions & 1 deletion aws/resource_aws_spot_instance_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ func resourceAwsSpotInstanceRequest() *schema.Resource {
Optional: true,
ForceNew: true,
}

s["instance_interruption_behaviour"] = &schema.Schema{
Type: schema.TypeString,
Optional: true,
Default: "terminate",
ForceNew: true,
}
return s
}(),
}
Expand All @@ -95,6 +100,7 @@ func resourceAwsSpotInstanceRequestCreate(d *schema.ResourceData, meta interface
spotOpts := &ec2.RequestSpotInstancesInput{
SpotPrice: aws.String(d.Get("spot_price").(string)),
Type: aws.String(d.Get("spot_type").(string)),
InstanceInterruptionBehavior: aws.String(d.Get("instance_interruption_behaviour").(string)),

// Though the AWS API supports creating spot instance requests for multiple
// instances, for TF purposes we fix this to one instance per request.
Expand Down Expand Up @@ -229,6 +235,7 @@ func resourceAwsSpotInstanceRequestRead(d *schema.ResourceData, meta interface{}
d.Set("launch_group", request.LaunchGroup)
d.Set("block_duration_minutes", request.BlockDurationMinutes)
d.Set("tags", tagsToMap(request.Tags))
d.Set("instance_interruption_behaviour", request.InstanceInterruptionBehavior)

return nil
}
Expand Down
2 changes: 2 additions & 0 deletions aws/resource_aws_spot_instance_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func TestAccAWSSpotInstanceRequest_basic(t *testing.T) {
"aws_spot_instance_request.foo", "spot_bid_status", "fulfilled"),
resource.TestCheckResourceAttr(
"aws_spot_instance_request.foo", "spot_request_state", "active"),
resource.TestCheckResourceAttr(
"aws_spot_instance_request.foo", "instance_interruption_behaviour", "terminate"),
),
},
},
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/spot_instance_request.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Spot Instance Requests support all the same arguments as
* `block_duration_minutes` - (Optional) The required duration for the Spot instances, in minutes. This value must be a multiple of 60 (60, 120, 180, 240, 300, or 360).
The duration period starts as soon as your Spot instance receives its instance ID. At the end of the duration period, Amazon EC2 marks the Spot instance for termination and provides a Spot instance termination notice, which gives the instance a two-minute warning before it terminates.
Note that you can't specify an Availability Zone group or a launch group if you specify a duration.
* `instance_interruption_behavior` - (Optional) Indicates whether a Spot instance stops or terminates when it is interrupted. Default is `terminate` as this is the current AWS behaviour.

### Timeouts

Expand Down

0 comments on commit f677c37

Please sign in to comment.