Skip to content

Commit

Permalink
Add test for stopping spot instance requests
Browse files Browse the repository at this point in the history
Using an EBS backed AMI for testing stoppable spot requests.
  • Loading branch information
Tom Elliff committed Oct 20, 2017
1 parent a61d2ed commit 11584aa
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions aws/resource_aws_spot_instance_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,31 @@ func testAccCheckAWSSpotInstanceRequestAttributesVPC(
}
}

func TestAccAWSSpotInstanceRequestStopInterrupt(t *testing.T) {
var sir ec2.SpotInstanceRequest

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSSpotInstanceRequestDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSSpotInstanceRequestStopInterruptConfig(),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSpotInstanceRequestExists(
"aws_spot_instance_request.foo", &sir),
resource.TestCheckResourceAttr(
"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", "stop"),
),
},
},
})
}

func testAccAWSSpotInstanceRequestConfig(rInt int) string {
return fmt.Sprintf(`
resource "aws_key_pair" "debugging" {
Expand Down Expand Up @@ -522,3 +547,21 @@ func testAccAWSSpotInstanceRequestConfig_SubnetAndSGAndPublicIpAddress(rInt int)
}
}`, rInt, rInt, rInt)
}

func testAccAWSSpotInstanceRequestStopInterruptConfig() string {
return fmt.Sprintf(`
resource "aws_spot_instance_request" "foo" {
ami = "ami-19e92861"
instance_type = "m3.medium"
// base price is $0.067 hourly, so bidding above that should theoretically
// always fulfill
spot_price = "0.07"
// we wait for fulfillment because we want to inspect the launched instance
// and verify termination behavior
wait_for_fulfillment = true
instance_interruption_behaviour = "stop"
}`)
}

0 comments on commit 11584aa

Please sign in to comment.