Skip to content

Commit

Permalink
Merge pull request #1847 from mikekap/iib-for-fleets
Browse files Browse the repository at this point in the history
resource/aws_spot_fleet_request: Add support for instance_interruption_behaviour
  • Loading branch information
Ninir authored Oct 12, 2017
2 parents cece5ff + dbd3504 commit 22426e0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
8 changes: 8 additions & 0 deletions aws/resource_aws_spot_fleet_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ func resourceAwsSpotFleetRequest() *schema.Resource {
Default: "Default",
ForceNew: false,
},
"instance_interruption_behaviour": {
Type: schema.TypeString,
Optional: true,
Default: "terminate",
ForceNew: true,
},
"spot_price": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -552,6 +558,7 @@ func resourceAwsSpotFleetRequestCreate(d *schema.ResourceData, meta interface{})
ClientToken: aws.String(resource.UniqueId()),
TerminateInstancesWithExpiration: aws.Bool(d.Get("terminate_instances_with_expiration").(bool)),
ReplaceUnhealthyInstances: aws.Bool(d.Get("replace_unhealthy_instances").(bool)),
InstanceInterruptionBehavior: aws.String(d.Get("instance_interruption_behaviour").(string)),
}

if v, ok := d.GetOk("excess_capacity_termination_policy"); ok {
Expand Down Expand Up @@ -788,6 +795,7 @@ func resourceAwsSpotFleetRequestRead(d *schema.ResourceData, meta interface{}) e
}

d.Set("replace_unhealthy_instances", config.ReplaceUnhealthyInstances)
d.Set("instance_interruption_behaviour", config.InstanceInterruptionBehavior)
d.Set("launch_specification", launchSpecsToSet(config.LaunchSpecifications, conn))

return nil
Expand Down
26 changes: 26 additions & 0 deletions aws/resource_aws_spot_fleet_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,31 @@ func TestAccAWSSpotFleetRequest_associatePublicIpAddress(t *testing.T) {
})
}

func TestAccAWSSpotFleetRequest_instanceInterruptionBehavior(t *testing.T) {
var sfr ec2.SpotFleetRequestConfig
rName := acctest.RandString(10)
rInt := acctest.RandInt()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSSpotFleetRequestDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSSpotFleetRequestConfig(rName, rInt),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAWSSpotFleetRequestExists(
"aws_spot_fleet_request.foo", &sfr),
resource.TestCheckResourceAttr(
"aws_spot_fleet_request.foo", "spot_request_state", "active"),
resource.TestCheckResourceAttr(
"aws_spot_fleet_request.foo", "instance_interruption_behaviour", "stop"),
),
},
},
})
}

func TestAccAWSSpotFleetRequest_changePriceForcesNewRequest(t *testing.T) {
var before, after ec2.SpotFleetRequestConfig
rName := acctest.RandString(10)
Expand Down Expand Up @@ -609,6 +634,7 @@ resource "aws_spot_fleet_request" "foo" {
target_capacity = 2
valid_until = "2019-11-04T20:44:20Z"
terminate_instances_with_expiration = true
instance_interruption_behaviour = "stop"
wait_for_fulfillment = true
launch_specification {
instance_type = "m1.small"
Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/spot_fleet_request.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ lowestPrice.
request is decreased below the current size of the Spot fleet.
* `terminate_instances_with_expiration` - Indicates whether running Spot
instances should be terminated when the Spot fleet request expires.
* `instance_interruption_behavior` - (Optional) Indicates whether a Spot
instance stops or terminates when it is interrupted. Default is
`terminate`.
* `valid_until` - The end date and time of the request, in UTC ISO8601 format
(for example, YYYY-MM-DDTHH:MM:SSZ). At this point, no new Spot instance
requests are placed or enabled to fulfill the request. Defaults to 24 hours.
Expand Down

0 comments on commit 22426e0

Please sign in to comment.