-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass key_name and subnetId to spot instance request - resolves issue #2919 #2954
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ func TestAccAWSSpotInstanceRequest_basic(t *testing.T) { | |
testAccCheckAWSSpotInstanceRequestExists( | ||
"aws_spot_instance_request.foo", &sir), | ||
testAccCheckAWSSpotInstanceRequestAttributes(&sir), | ||
testCheckKeyPair("tmp-key", &sir), | ||
resource.TestCheckResourceAttr( | ||
"aws_spot_instance_request.foo", "spot_bid_status", "fulfilled"), | ||
resource.TestCheckResourceAttr( | ||
|
@@ -35,6 +36,45 @@ func TestAccAWSSpotInstanceRequest_basic(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccAWSSpotInstanceRequest_vpc(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A new acceptance test |
||
var sir ec2.SpotInstanceRequest | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckAWSSpotInstanceRequestDestroy, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccAWSSpotInstanceRequestConfigVPC, | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAWSSpotInstanceRequestExists( | ||
"aws_spot_instance_request.foo_VPC", &sir), | ||
testAccCheckAWSSpotInstanceRequestAttributes(&sir), | ||
testCheckKeyPair("tmp-key", &sir), | ||
testAccCheckAWSSpotInstanceRequestAttributesVPC(&sir), | ||
resource.TestCheckResourceAttr( | ||
"aws_spot_instance_request.foo_VPC", "spot_bid_status", "fulfilled"), | ||
resource.TestCheckResourceAttr( | ||
"aws_spot_instance_request.foo_VPC", "spot_request_state", "active"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testCheckKeyPair(keyName string, sir *ec2.SpotInstanceRequest) resource.TestCheckFunc { | ||
return func(*terraform.State) error { | ||
if sir.LaunchSpecification.KeyName == nil { | ||
return fmt.Errorf("No Key Pair found, expected(%s)", keyName) | ||
} | ||
if sir.LaunchSpecification.KeyName != nil && *sir.LaunchSpecification.KeyName != keyName { | ||
return fmt.Errorf("Bad key name, expected (%s), got (%s)", keyName, *sir.LaunchSpecification.KeyName) | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
func testAccCheckAWSSpotInstanceRequestDestroy(s *terraform.State) error { | ||
conn := testAccProvider.Meta().(*AWSClient).ec2conn | ||
|
||
|
@@ -138,10 +178,26 @@ func testAccCheckAWSSpotInstanceRequestAttributes( | |
} | ||
} | ||
|
||
func testAccCheckAWSSpotInstanceRequestAttributesVPC( | ||
sir *ec2.SpotInstanceRequest) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
if sir.LaunchSpecification.SubnetID == nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return fmt.Errorf("SubnetID was not passed, but should have been for this instance to belong to a VPC") | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
const testAccAWSSpotInstanceRequestConfig = ` | ||
resource "aws_key_pair" "debugging" { | ||
key_name = "tmp-key" | ||
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 phodgson@thoughtworks.com" | ||
} | ||
|
||
resource "aws_spot_instance_request" "foo" { | ||
ami = "ami-4fccb37f" | ||
instance_type = "m1.small" | ||
key_name = "${aws_key_pair.debugging.key_name}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed the default spot test to validate that passing a |
||
|
||
// base price is $0.044 hourly, so bidding above that should theoretically | ||
// always fulfill | ||
|
@@ -156,3 +212,40 @@ resource "aws_spot_instance_request" "foo" { | |
} | ||
} | ||
` | ||
|
||
const testAccAWSSpotInstanceRequestConfigVPC = ` | ||
resource "aws_vpc" "foo_VPC" { | ||
cidr_block = "10.1.0.0/16" | ||
} | ||
|
||
resource "aws_subnet" "foo_VPC" { | ||
cidr_block = "10.1.1.0/24" | ||
vpc_id = "${aws_vpc.foo_VPC.id}" | ||
} | ||
|
||
resource "aws_key_pair" "debugging" { | ||
key_name = "tmp-key" | ||
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 phodgson@thoughtworks.com" | ||
} | ||
|
||
resource "aws_spot_instance_request" "foo_VPC" { | ||
ami = "ami-4fccb37f" | ||
instance_type = "m1.small" | ||
key_name = "${aws_key_pair.debugging.key_name}" | ||
|
||
// base price is $0.044 hourly, so bidding above that should theoretically | ||
// always fulfill | ||
spot_price = "0.05" | ||
|
||
// VPC settings | ||
subnet_id = "${aws_subnet.foo_VPC.id}" | ||
|
||
// we wait for fulfillment because we want to inspect the launched instance | ||
// and verify termination behavior | ||
wait_for_fulfillment = true | ||
|
||
tags { | ||
Name = "terraform-test-VPC" | ||
} | ||
} | ||
` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SubnetId: