provider/aws: spot_instance_request
This is an iteration on the great work done by @dalehamel in PRs #2095
and #2109.
The core team went back and forth on how to best model Spot Instance
Requests, requesting and then rejecting a separate-resource
implementation in #2109.
After more internal discussion, we landed once again on a separate
resource to model Spot Instance Requests. Out of respect for
@dalehamel's already-significant donated time, with this I'm attempting
to pick up the work to take this across the finish line.
Important architectural decisions represented here:
* Spot Instance Requests are always of type "persistent", to properly
match Terraform's declarative model.
* The spot_instance_request resource exports several attributes that
are expected to be constantly changing as the spot market changes:
spot_bid_status, spot_request_state, and instance_id. Creating
additional resource dependencies based on these attributes is not
recommended, as Terraform diffs will be continually generated to keep
up with the live changes.
* When a Spot Instance Request is deleted/canceled, an attempt is made
to terminate the last-known attached spot instance. Race conditions
dictate that this attempt cannot guarantee that the associated spot
instance is terminated immediately.
Implementation notes:
* This version of aws_spot_instance_request borrows a lot of common
code from aws_instance.
* In order to facilitate borrowing, we introduce `awsInstanceOpts`, an
internal representation of instance details that's meant to be shared
between resources. The goal here would be to refactor ASG Launch
Configurations to use the same struct.
* The new aws_spot_instance_request acc. test is passing.
* All aws_instance acc. tests remain passing.
2015-06-05 17:12:09 +02:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
|
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
|
|
|
"github.com/aws/aws-sdk-go/service/ec2"
|
2017-02-03 00:57:50 +01:00
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
provider/aws: spot_instance_request
This is an iteration on the great work done by @dalehamel in PRs #2095
and #2109.
The core team went back and forth on how to best model Spot Instance
Requests, requesting and then rejecting a separate-resource
implementation in #2109.
After more internal discussion, we landed once again on a separate
resource to model Spot Instance Requests. Out of respect for
@dalehamel's already-significant donated time, with this I'm attempting
to pick up the work to take this across the finish line.
Important architectural decisions represented here:
* Spot Instance Requests are always of type "persistent", to properly
match Terraform's declarative model.
* The spot_instance_request resource exports several attributes that
are expected to be constantly changing as the spot market changes:
spot_bid_status, spot_request_state, and instance_id. Creating
additional resource dependencies based on these attributes is not
recommended, as Terraform diffs will be continually generated to keep
up with the live changes.
* When a Spot Instance Request is deleted/canceled, an attempt is made
to terminate the last-known attached spot instance. Race conditions
dictate that this attempt cannot guarantee that the associated spot
instance is terminated immediately.
Implementation notes:
* This version of aws_spot_instance_request borrows a lot of common
code from aws_instance.
* In order to facilitate borrowing, we introduce `awsInstanceOpts`, an
internal representation of instance details that's meant to be shared
between resources. The goal here would be to refactor ASG Launch
Configurations to use the same struct.
* The new aws_spot_instance_request acc. test is passing.
* All aws_instance acc. tests remain passing.
2015-06-05 17:12:09 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccAWSSpotInstanceRequest_basic(t *testing.T) {
|
|
|
|
var sir ec2.SpotInstanceRequest
|
2017-02-03 00:57:50 +01:00
|
|
|
rInt := acctest.RandInt()
|
provider/aws: spot_instance_request
This is an iteration on the great work done by @dalehamel in PRs #2095
and #2109.
The core team went back and forth on how to best model Spot Instance
Requests, requesting and then rejecting a separate-resource
implementation in #2109.
After more internal discussion, we landed once again on a separate
resource to model Spot Instance Requests. Out of respect for
@dalehamel's already-significant donated time, with this I'm attempting
to pick up the work to take this across the finish line.
Important architectural decisions represented here:
* Spot Instance Requests are always of type "persistent", to properly
match Terraform's declarative model.
* The spot_instance_request resource exports several attributes that
are expected to be constantly changing as the spot market changes:
spot_bid_status, spot_request_state, and instance_id. Creating
additional resource dependencies based on these attributes is not
recommended, as Terraform diffs will be continually generated to keep
up with the live changes.
* When a Spot Instance Request is deleted/canceled, an attempt is made
to terminate the last-known attached spot instance. Race conditions
dictate that this attempt cannot guarantee that the associated spot
instance is terminated immediately.
Implementation notes:
* This version of aws_spot_instance_request borrows a lot of common
code from aws_instance.
* In order to facilitate borrowing, we introduce `awsInstanceOpts`, an
internal representation of instance details that's meant to be shared
between resources. The goal here would be to refactor ASG Launch
Configurations to use the same struct.
* The new aws_spot_instance_request acc. test is passing.
* All aws_instance acc. tests remain passing.
2015-06-05 17:12:09 +02:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSSpotInstanceRequestDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-02-03 00:57:50 +01:00
|
|
|
{
|
|
|
|
Config: testAccAWSSpotInstanceRequestConfig(rInt),
|
provider/aws: spot_instance_request
This is an iteration on the great work done by @dalehamel in PRs #2095
and #2109.
The core team went back and forth on how to best model Spot Instance
Requests, requesting and then rejecting a separate-resource
implementation in #2109.
After more internal discussion, we landed once again on a separate
resource to model Spot Instance Requests. Out of respect for
@dalehamel's already-significant donated time, with this I'm attempting
to pick up the work to take this across the finish line.
Important architectural decisions represented here:
* Spot Instance Requests are always of type "persistent", to properly
match Terraform's declarative model.
* The spot_instance_request resource exports several attributes that
are expected to be constantly changing as the spot market changes:
spot_bid_status, spot_request_state, and instance_id. Creating
additional resource dependencies based on these attributes is not
recommended, as Terraform diffs will be continually generated to keep
up with the live changes.
* When a Spot Instance Request is deleted/canceled, an attempt is made
to terminate the last-known attached spot instance. Race conditions
dictate that this attempt cannot guarantee that the associated spot
instance is terminated immediately.
Implementation notes:
* This version of aws_spot_instance_request borrows a lot of common
code from aws_instance.
* In order to facilitate borrowing, we introduce `awsInstanceOpts`, an
internal representation of instance details that's meant to be shared
between resources. The goal here would be to refactor ASG Launch
Configurations to use the same struct.
* The new aws_spot_instance_request acc. test is passing.
* All aws_instance acc. tests remain passing.
2015-06-05 17:12:09 +02:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSSpotInstanceRequestExists(
|
|
|
|
"aws_spot_instance_request.foo", &sir),
|
|
|
|
testAccCheckAWSSpotInstanceRequestAttributes(&sir),
|
2017-02-03 00:57:50 +01:00
|
|
|
testCheckKeyPair(fmt.Sprintf("tmp-key-%d", rInt), &sir),
|
provider/aws: spot_instance_request
This is an iteration on the great work done by @dalehamel in PRs #2095
and #2109.
The core team went back and forth on how to best model Spot Instance
Requests, requesting and then rejecting a separate-resource
implementation in #2109.
After more internal discussion, we landed once again on a separate
resource to model Spot Instance Requests. Out of respect for
@dalehamel's already-significant donated time, with this I'm attempting
to pick up the work to take this across the finish line.
Important architectural decisions represented here:
* Spot Instance Requests are always of type "persistent", to properly
match Terraform's declarative model.
* The spot_instance_request resource exports several attributes that
are expected to be constantly changing as the spot market changes:
spot_bid_status, spot_request_state, and instance_id. Creating
additional resource dependencies based on these attributes is not
recommended, as Terraform diffs will be continually generated to keep
up with the live changes.
* When a Spot Instance Request is deleted/canceled, an attempt is made
to terminate the last-known attached spot instance. Race conditions
dictate that this attempt cannot guarantee that the associated spot
instance is terminated immediately.
Implementation notes:
* This version of aws_spot_instance_request borrows a lot of common
code from aws_instance.
* In order to facilitate borrowing, we introduce `awsInstanceOpts`, an
internal representation of instance details that's meant to be shared
between resources. The goal here would be to refactor ASG Launch
Configurations to use the same struct.
* The new aws_spot_instance_request acc. test is passing.
* All aws_instance acc. tests remain passing.
2015-06-05 17:12:09 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_spot_instance_request.foo", "spot_bid_status", "fulfilled"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_spot_instance_request.foo", "spot_request_state", "active"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-11-26 12:56:04 +01:00
|
|
|
func TestAccAWSSpotInstanceRequest_withBlockDuration(t *testing.T) {
|
|
|
|
var sir ec2.SpotInstanceRequest
|
2017-02-03 00:57:50 +01:00
|
|
|
rInt := acctest.RandInt()
|
2015-11-26 12:56:04 +01:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSSpotInstanceRequestDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-02-03 00:57:50 +01:00
|
|
|
{
|
|
|
|
Config: testAccAWSSpotInstanceRequestConfig_withBlockDuration(rInt),
|
2015-11-26 12:56:04 +01:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSSpotInstanceRequestExists(
|
|
|
|
"aws_spot_instance_request.foo", &sir),
|
|
|
|
testAccCheckAWSSpotInstanceRequestAttributes(&sir),
|
2017-02-03 00:57:50 +01:00
|
|
|
testCheckKeyPair(fmt.Sprintf("tmp-key-%d", rInt), &sir),
|
2015-11-26 12:56:04 +01:00
|
|
|
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", "block_duration_minutes", "60"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-08-06 21:22:10 +02:00
|
|
|
func TestAccAWSSpotInstanceRequest_vpc(t *testing.T) {
|
|
|
|
var sir ec2.SpotInstanceRequest
|
2017-02-03 00:57:50 +01:00
|
|
|
rInt := acctest.RandInt()
|
2015-08-06 21:22:10 +02:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSSpotInstanceRequestDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-02-03 00:57:50 +01:00
|
|
|
{
|
|
|
|
Config: testAccAWSSpotInstanceRequestConfigVPC(rInt),
|
2015-08-06 21:22:10 +02:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSSpotInstanceRequestExists(
|
|
|
|
"aws_spot_instance_request.foo_VPC", &sir),
|
|
|
|
testAccCheckAWSSpotInstanceRequestAttributes(&sir),
|
2017-02-03 00:57:50 +01:00
|
|
|
testCheckKeyPair(fmt.Sprintf("tmp-key-%d", rInt), &sir),
|
2015-08-06 21:22:10 +02:00
|
|
|
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"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-11-16 22:11:44 +01:00
|
|
|
func TestAccAWSSpotInstanceRequest_SubnetAndSG(t *testing.T) {
|
|
|
|
var sir ec2.SpotInstanceRequest
|
2017-02-03 00:57:50 +01:00
|
|
|
rInt := acctest.RandInt()
|
2015-11-16 22:11:44 +01:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSSpotInstanceRequestDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-02-03 00:57:50 +01:00
|
|
|
{
|
|
|
|
Config: testAccAWSSpotInstanceRequestConfig_SubnetAndSG(rInt),
|
2015-11-16 22:11:44 +01:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSSpotInstanceRequestExists(
|
|
|
|
"aws_spot_instance_request.foo", &sir),
|
2017-02-03 00:57:50 +01:00
|
|
|
testAccCheckAWSSpotInstanceRequest_InstanceAttributes(&sir, rInt),
|
2015-11-16 22:11:44 +01:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-08-06 21:22:10 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
provider/aws: spot_instance_request
This is an iteration on the great work done by @dalehamel in PRs #2095
and #2109.
The core team went back and forth on how to best model Spot Instance
Requests, requesting and then rejecting a separate-resource
implementation in #2109.
After more internal discussion, we landed once again on a separate
resource to model Spot Instance Requests. Out of respect for
@dalehamel's already-significant donated time, with this I'm attempting
to pick up the work to take this across the finish line.
Important architectural decisions represented here:
* Spot Instance Requests are always of type "persistent", to properly
match Terraform's declarative model.
* The spot_instance_request resource exports several attributes that
are expected to be constantly changing as the spot market changes:
spot_bid_status, spot_request_state, and instance_id. Creating
additional resource dependencies based on these attributes is not
recommended, as Terraform diffs will be continually generated to keep
up with the live changes.
* When a Spot Instance Request is deleted/canceled, an attempt is made
to terminate the last-known attached spot instance. Race conditions
dictate that this attempt cannot guarantee that the associated spot
instance is terminated immediately.
Implementation notes:
* This version of aws_spot_instance_request borrows a lot of common
code from aws_instance.
* In order to facilitate borrowing, we introduce `awsInstanceOpts`, an
internal representation of instance details that's meant to be shared
between resources. The goal here would be to refactor ASG Launch
Configurations to use the same struct.
* The new aws_spot_instance_request acc. test is passing.
* All aws_instance acc. tests remain passing.
2015-06-05 17:12:09 +02:00
|
|
|
func testAccCheckAWSSpotInstanceRequestDestroy(s *terraform.State) error {
|
|
|
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
|
|
|
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
|
|
if rs.Type != "aws_spot_instance_request" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
req := &ec2.DescribeSpotInstanceRequestsInput{
|
2015-08-17 20:27:16 +02:00
|
|
|
SpotInstanceRequestIds: []*string{aws.String(rs.Primary.ID)},
|
provider/aws: spot_instance_request
This is an iteration on the great work done by @dalehamel in PRs #2095
and #2109.
The core team went back and forth on how to best model Spot Instance
Requests, requesting and then rejecting a separate-resource
implementation in #2109.
After more internal discussion, we landed once again on a separate
resource to model Spot Instance Requests. Out of respect for
@dalehamel's already-significant donated time, with this I'm attempting
to pick up the work to take this across the finish line.
Important architectural decisions represented here:
* Spot Instance Requests are always of type "persistent", to properly
match Terraform's declarative model.
* The spot_instance_request resource exports several attributes that
are expected to be constantly changing as the spot market changes:
spot_bid_status, spot_request_state, and instance_id. Creating
additional resource dependencies based on these attributes is not
recommended, as Terraform diffs will be continually generated to keep
up with the live changes.
* When a Spot Instance Request is deleted/canceled, an attempt is made
to terminate the last-known attached spot instance. Race conditions
dictate that this attempt cannot guarantee that the associated spot
instance is terminated immediately.
Implementation notes:
* This version of aws_spot_instance_request borrows a lot of common
code from aws_instance.
* In order to facilitate borrowing, we introduce `awsInstanceOpts`, an
internal representation of instance details that's meant to be shared
between resources. The goal here would be to refactor ASG Launch
Configurations to use the same struct.
* The new aws_spot_instance_request acc. test is passing.
* All aws_instance acc. tests remain passing.
2015-06-05 17:12:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := conn.DescribeSpotInstanceRequests(req)
|
2015-12-22 18:08:09 +01:00
|
|
|
var s *ec2.SpotInstanceRequest
|
provider/aws: spot_instance_request
This is an iteration on the great work done by @dalehamel in PRs #2095
and #2109.
The core team went back and forth on how to best model Spot Instance
Requests, requesting and then rejecting a separate-resource
implementation in #2109.
After more internal discussion, we landed once again on a separate
resource to model Spot Instance Requests. Out of respect for
@dalehamel's already-significant donated time, with this I'm attempting
to pick up the work to take this across the finish line.
Important architectural decisions represented here:
* Spot Instance Requests are always of type "persistent", to properly
match Terraform's declarative model.
* The spot_instance_request resource exports several attributes that
are expected to be constantly changing as the spot market changes:
spot_bid_status, spot_request_state, and instance_id. Creating
additional resource dependencies based on these attributes is not
recommended, as Terraform diffs will be continually generated to keep
up with the live changes.
* When a Spot Instance Request is deleted/canceled, an attempt is made
to terminate the last-known attached spot instance. Race conditions
dictate that this attempt cannot guarantee that the associated spot
instance is terminated immediately.
Implementation notes:
* This version of aws_spot_instance_request borrows a lot of common
code from aws_instance.
* In order to facilitate borrowing, we introduce `awsInstanceOpts`, an
internal representation of instance details that's meant to be shared
between resources. The goal here would be to refactor ASG Launch
Configurations to use the same struct.
* The new aws_spot_instance_request acc. test is passing.
* All aws_instance acc. tests remain passing.
2015-06-05 17:12:09 +02:00
|
|
|
if err == nil {
|
2015-12-22 18:08:09 +01:00
|
|
|
for _, sir := range resp.SpotInstanceRequests {
|
|
|
|
if sir.SpotInstanceRequestId != nil && *sir.SpotInstanceRequestId == rs.Primary.ID {
|
|
|
|
s = sir
|
|
|
|
}
|
|
|
|
continue
|
provider/aws: spot_instance_request
This is an iteration on the great work done by @dalehamel in PRs #2095
and #2109.
The core team went back and forth on how to best model Spot Instance
Requests, requesting and then rejecting a separate-resource
implementation in #2109.
After more internal discussion, we landed once again on a separate
resource to model Spot Instance Requests. Out of respect for
@dalehamel's already-significant donated time, with this I'm attempting
to pick up the work to take this across the finish line.
Important architectural decisions represented here:
* Spot Instance Requests are always of type "persistent", to properly
match Terraform's declarative model.
* The spot_instance_request resource exports several attributes that
are expected to be constantly changing as the spot market changes:
spot_bid_status, spot_request_state, and instance_id. Creating
additional resource dependencies based on these attributes is not
recommended, as Terraform diffs will be continually generated to keep
up with the live changes.
* When a Spot Instance Request is deleted/canceled, an attempt is made
to terminate the last-known attached spot instance. Race conditions
dictate that this attempt cannot guarantee that the associated spot
instance is terminated immediately.
Implementation notes:
* This version of aws_spot_instance_request borrows a lot of common
code from aws_instance.
* In order to facilitate borrowing, we introduce `awsInstanceOpts`, an
internal representation of instance details that's meant to be shared
between resources. The goal here would be to refactor ASG Launch
Configurations to use the same struct.
* The new aws_spot_instance_request acc. test is passing.
* All aws_instance acc. tests remain passing.
2015-06-05 17:12:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-22 18:08:09 +01:00
|
|
|
if s == nil {
|
|
|
|
// not found
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if *s.State == "canceled" {
|
|
|
|
// Requests stick around for a while, so we make sure it's cancelled
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
provider/aws: spot_instance_request
This is an iteration on the great work done by @dalehamel in PRs #2095
and #2109.
The core team went back and forth on how to best model Spot Instance
Requests, requesting and then rejecting a separate-resource
implementation in #2109.
After more internal discussion, we landed once again on a separate
resource to model Spot Instance Requests. Out of respect for
@dalehamel's already-significant donated time, with this I'm attempting
to pick up the work to take this across the finish line.
Important architectural decisions represented here:
* Spot Instance Requests are always of type "persistent", to properly
match Terraform's declarative model.
* The spot_instance_request resource exports several attributes that
are expected to be constantly changing as the spot market changes:
spot_bid_status, spot_request_state, and instance_id. Creating
additional resource dependencies based on these attributes is not
recommended, as Terraform diffs will be continually generated to keep
up with the live changes.
* When a Spot Instance Request is deleted/canceled, an attempt is made
to terminate the last-known attached spot instance. Race conditions
dictate that this attempt cannot guarantee that the associated spot
instance is terminated immediately.
Implementation notes:
* This version of aws_spot_instance_request borrows a lot of common
code from aws_instance.
* In order to facilitate borrowing, we introduce `awsInstanceOpts`, an
internal representation of instance details that's meant to be shared
between resources. The goal here would be to refactor ASG Launch
Configurations to use the same struct.
* The new aws_spot_instance_request acc. test is passing.
* All aws_instance acc. tests remain passing.
2015-06-05 17:12:09 +02:00
|
|
|
// Verify the error is what we expect
|
|
|
|
ec2err, ok := err.(awserr.Error)
|
|
|
|
if !ok {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if ec2err.Code() != "InvalidSpotInstanceRequestID.NotFound" {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now check if the associated Spot Instance was also destroyed
|
|
|
|
instId := rs.Primary.Attributes["spot_instance_id"]
|
|
|
|
instResp, instErr := conn.DescribeInstances(&ec2.DescribeInstancesInput{
|
2015-08-17 20:27:16 +02:00
|
|
|
InstanceIds: []*string{aws.String(instId)},
|
provider/aws: spot_instance_request
This is an iteration on the great work done by @dalehamel in PRs #2095
and #2109.
The core team went back and forth on how to best model Spot Instance
Requests, requesting and then rejecting a separate-resource
implementation in #2109.
After more internal discussion, we landed once again on a separate
resource to model Spot Instance Requests. Out of respect for
@dalehamel's already-significant donated time, with this I'm attempting
to pick up the work to take this across the finish line.
Important architectural decisions represented here:
* Spot Instance Requests are always of type "persistent", to properly
match Terraform's declarative model.
* The spot_instance_request resource exports several attributes that
are expected to be constantly changing as the spot market changes:
spot_bid_status, spot_request_state, and instance_id. Creating
additional resource dependencies based on these attributes is not
recommended, as Terraform diffs will be continually generated to keep
up with the live changes.
* When a Spot Instance Request is deleted/canceled, an attempt is made
to terminate the last-known attached spot instance. Race conditions
dictate that this attempt cannot guarantee that the associated spot
instance is terminated immediately.
Implementation notes:
* This version of aws_spot_instance_request borrows a lot of common
code from aws_instance.
* In order to facilitate borrowing, we introduce `awsInstanceOpts`, an
internal representation of instance details that's meant to be shared
between resources. The goal here would be to refactor ASG Launch
Configurations to use the same struct.
* The new aws_spot_instance_request acc. test is passing.
* All aws_instance acc. tests remain passing.
2015-06-05 17:12:09 +02:00
|
|
|
})
|
|
|
|
if instErr == nil {
|
|
|
|
if len(instResp.Reservations) > 0 {
|
|
|
|
return fmt.Errorf("Instance still exists.")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify the error is what we expect
|
|
|
|
ec2err, ok = err.(awserr.Error)
|
|
|
|
if !ok {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if ec2err.Code() != "InvalidInstanceID.NotFound" {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckAWSSpotInstanceRequestExists(
|
|
|
|
n string, sir *ec2.SpotInstanceRequest) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
rs, ok := s.RootModule().Resources[n]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", n)
|
|
|
|
}
|
|
|
|
|
|
|
|
if rs.Primary.ID == "" {
|
|
|
|
return fmt.Errorf("No SNS subscription with that ARN exists")
|
|
|
|
}
|
|
|
|
|
|
|
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
|
|
|
|
|
|
|
params := &ec2.DescribeSpotInstanceRequestsInput{
|
2015-08-17 20:27:16 +02:00
|
|
|
SpotInstanceRequestIds: []*string{&rs.Primary.ID},
|
provider/aws: spot_instance_request
This is an iteration on the great work done by @dalehamel in PRs #2095
and #2109.
The core team went back and forth on how to best model Spot Instance
Requests, requesting and then rejecting a separate-resource
implementation in #2109.
After more internal discussion, we landed once again on a separate
resource to model Spot Instance Requests. Out of respect for
@dalehamel's already-significant donated time, with this I'm attempting
to pick up the work to take this across the finish line.
Important architectural decisions represented here:
* Spot Instance Requests are always of type "persistent", to properly
match Terraform's declarative model.
* The spot_instance_request resource exports several attributes that
are expected to be constantly changing as the spot market changes:
spot_bid_status, spot_request_state, and instance_id. Creating
additional resource dependencies based on these attributes is not
recommended, as Terraform diffs will be continually generated to keep
up with the live changes.
* When a Spot Instance Request is deleted/canceled, an attempt is made
to terminate the last-known attached spot instance. Race conditions
dictate that this attempt cannot guarantee that the associated spot
instance is terminated immediately.
Implementation notes:
* This version of aws_spot_instance_request borrows a lot of common
code from aws_instance.
* In order to facilitate borrowing, we introduce `awsInstanceOpts`, an
internal representation of instance details that's meant to be shared
between resources. The goal here would be to refactor ASG Launch
Configurations to use the same struct.
* The new aws_spot_instance_request acc. test is passing.
* All aws_instance acc. tests remain passing.
2015-06-05 17:12:09 +02:00
|
|
|
}
|
|
|
|
resp, err := conn.DescribeSpotInstanceRequests(params)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if v := len(resp.SpotInstanceRequests); v != 1 {
|
|
|
|
return fmt.Errorf("Expected 1 request returned, got %d", v)
|
|
|
|
}
|
|
|
|
|
|
|
|
*sir = *resp.SpotInstanceRequests[0]
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckAWSSpotInstanceRequestAttributes(
|
|
|
|
sir *ec2.SpotInstanceRequest) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
if *sir.SpotPrice != "0.050000" {
|
|
|
|
return fmt.Errorf("Unexpected spot price: %s", *sir.SpotPrice)
|
|
|
|
}
|
|
|
|
if *sir.State != "active" {
|
|
|
|
return fmt.Errorf("Unexpected request state: %s", *sir.State)
|
|
|
|
}
|
|
|
|
if *sir.Status.Code != "fulfilled" {
|
|
|
|
return fmt.Errorf("Unexpected bid status: %s", *sir.State)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-16 22:11:44 +01:00
|
|
|
func testAccCheckAWSSpotInstanceRequest_InstanceAttributes(
|
2017-02-03 00:57:50 +01:00
|
|
|
sir *ec2.SpotInstanceRequest, rInt int) resource.TestCheckFunc {
|
2015-11-16 22:11:44 +01:00
|
|
|
return func(s *terraform.State) error {
|
|
|
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
|
|
|
resp, err := conn.DescribeInstances(&ec2.DescribeInstancesInput{
|
|
|
|
InstanceIds: []*string{sir.InstanceId},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidInstanceID.NotFound" {
|
|
|
|
return fmt.Errorf("Spot Instance not found")
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// If nothing was found, then return no state
|
|
|
|
if len(resp.Reservations) == 0 {
|
|
|
|
return fmt.Errorf("Spot Instance not found")
|
|
|
|
}
|
|
|
|
|
|
|
|
instance := resp.Reservations[0].Instances[0]
|
|
|
|
|
|
|
|
var sgMatch bool
|
|
|
|
for _, s := range instance.SecurityGroups {
|
|
|
|
// Hardcoded name for the security group that should be added inside the
|
|
|
|
// VPC
|
2017-02-03 00:57:50 +01:00
|
|
|
if *s.GroupName == fmt.Sprintf("tf_test_sg_ssh-%d", rInt) {
|
2015-11-16 22:11:44 +01:00
|
|
|
sgMatch = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !sgMatch {
|
2017-02-03 00:57:50 +01:00
|
|
|
return fmt.Errorf("Error in matching Spot Instance Security Group, expected 'tf_test_sg_ssh-%d', got %s", rInt, instance.SecurityGroups)
|
2015-11-16 22:11:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-06 21:22:10 +02:00
|
|
|
func testAccCheckAWSSpotInstanceRequestAttributesVPC(
|
|
|
|
sir *ec2.SpotInstanceRequest) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
2015-08-31 16:34:34 +02:00
|
|
|
if sir.LaunchSpecification.SubnetId == nil {
|
2015-08-06 21:22:10 +02:00
|
|
|
return fmt.Errorf("SubnetID was not passed, but should have been for this instance to belong to a VPC")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-03 00:57:50 +01:00
|
|
|
func testAccAWSSpotInstanceRequestConfig(rInt int) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "aws_key_pair" "debugging" {
|
|
|
|
key_name = "tmp-key-%d"
|
|
|
|
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 phodgson@thoughtworks.com"
|
|
|
|
}
|
2015-08-06 21:22:10 +02:00
|
|
|
|
2017-02-03 00:57:50 +01:00
|
|
|
resource "aws_spot_instance_request" "foo" {
|
|
|
|
ami = "ami-4fccb37f"
|
|
|
|
instance_type = "m1.small"
|
|
|
|
key_name = "${aws_key_pair.debugging.key_name}"
|
provider/aws: spot_instance_request
This is an iteration on the great work done by @dalehamel in PRs #2095
and #2109.
The core team went back and forth on how to best model Spot Instance
Requests, requesting and then rejecting a separate-resource
implementation in #2109.
After more internal discussion, we landed once again on a separate
resource to model Spot Instance Requests. Out of respect for
@dalehamel's already-significant donated time, with this I'm attempting
to pick up the work to take this across the finish line.
Important architectural decisions represented here:
* Spot Instance Requests are always of type "persistent", to properly
match Terraform's declarative model.
* The spot_instance_request resource exports several attributes that
are expected to be constantly changing as the spot market changes:
spot_bid_status, spot_request_state, and instance_id. Creating
additional resource dependencies based on these attributes is not
recommended, as Terraform diffs will be continually generated to keep
up with the live changes.
* When a Spot Instance Request is deleted/canceled, an attempt is made
to terminate the last-known attached spot instance. Race conditions
dictate that this attempt cannot guarantee that the associated spot
instance is terminated immediately.
Implementation notes:
* This version of aws_spot_instance_request borrows a lot of common
code from aws_instance.
* In order to facilitate borrowing, we introduce `awsInstanceOpts`, an
internal representation of instance details that's meant to be shared
between resources. The goal here would be to refactor ASG Launch
Configurations to use the same struct.
* The new aws_spot_instance_request acc. test is passing.
* All aws_instance acc. tests remain passing.
2015-06-05 17:12:09 +02:00
|
|
|
|
2017-02-03 00:57:50 +01:00
|
|
|
// base price is $0.044 hourly, so bidding above that should theoretically
|
|
|
|
// always fulfill
|
|
|
|
spot_price = "0.05"
|
provider/aws: spot_instance_request
This is an iteration on the great work done by @dalehamel in PRs #2095
and #2109.
The core team went back and forth on how to best model Spot Instance
Requests, requesting and then rejecting a separate-resource
implementation in #2109.
After more internal discussion, we landed once again on a separate
resource to model Spot Instance Requests. Out of respect for
@dalehamel's already-significant donated time, with this I'm attempting
to pick up the work to take this across the finish line.
Important architectural decisions represented here:
* Spot Instance Requests are always of type "persistent", to properly
match Terraform's declarative model.
* The spot_instance_request resource exports several attributes that
are expected to be constantly changing as the spot market changes:
spot_bid_status, spot_request_state, and instance_id. Creating
additional resource dependencies based on these attributes is not
recommended, as Terraform diffs will be continually generated to keep
up with the live changes.
* When a Spot Instance Request is deleted/canceled, an attempt is made
to terminate the last-known attached spot instance. Race conditions
dictate that this attempt cannot guarantee that the associated spot
instance is terminated immediately.
Implementation notes:
* This version of aws_spot_instance_request borrows a lot of common
code from aws_instance.
* In order to facilitate borrowing, we introduce `awsInstanceOpts`, an
internal representation of instance details that's meant to be shared
between resources. The goal here would be to refactor ASG Launch
Configurations to use the same struct.
* The new aws_spot_instance_request acc. test is passing.
* All aws_instance acc. tests remain passing.
2015-06-05 17:12:09 +02:00
|
|
|
|
2017-02-03 00:57:50 +01:00
|
|
|
// we wait for fulfillment because we want to inspect the launched instance
|
|
|
|
// and verify termination behavior
|
|
|
|
wait_for_fulfillment = true
|
provider/aws: spot_instance_request
This is an iteration on the great work done by @dalehamel in PRs #2095
and #2109.
The core team went back and forth on how to best model Spot Instance
Requests, requesting and then rejecting a separate-resource
implementation in #2109.
After more internal discussion, we landed once again on a separate
resource to model Spot Instance Requests. Out of respect for
@dalehamel's already-significant donated time, with this I'm attempting
to pick up the work to take this across the finish line.
Important architectural decisions represented here:
* Spot Instance Requests are always of type "persistent", to properly
match Terraform's declarative model.
* The spot_instance_request resource exports several attributes that
are expected to be constantly changing as the spot market changes:
spot_bid_status, spot_request_state, and instance_id. Creating
additional resource dependencies based on these attributes is not
recommended, as Terraform diffs will be continually generated to keep
up with the live changes.
* When a Spot Instance Request is deleted/canceled, an attempt is made
to terminate the last-known attached spot instance. Race conditions
dictate that this attempt cannot guarantee that the associated spot
instance is terminated immediately.
Implementation notes:
* This version of aws_spot_instance_request borrows a lot of common
code from aws_instance.
* In order to facilitate borrowing, we introduce `awsInstanceOpts`, an
internal representation of instance details that's meant to be shared
between resources. The goal here would be to refactor ASG Launch
Configurations to use the same struct.
* The new aws_spot_instance_request acc. test is passing.
* All aws_instance acc. tests remain passing.
2015-06-05 17:12:09 +02:00
|
|
|
|
2017-02-03 00:57:50 +01:00
|
|
|
tags {
|
|
|
|
Name = "terraform-test"
|
|
|
|
}
|
|
|
|
}`, rInt)
|
provider/aws: spot_instance_request
This is an iteration on the great work done by @dalehamel in PRs #2095
and #2109.
The core team went back and forth on how to best model Spot Instance
Requests, requesting and then rejecting a separate-resource
implementation in #2109.
After more internal discussion, we landed once again on a separate
resource to model Spot Instance Requests. Out of respect for
@dalehamel's already-significant donated time, with this I'm attempting
to pick up the work to take this across the finish line.
Important architectural decisions represented here:
* Spot Instance Requests are always of type "persistent", to properly
match Terraform's declarative model.
* The spot_instance_request resource exports several attributes that
are expected to be constantly changing as the spot market changes:
spot_bid_status, spot_request_state, and instance_id. Creating
additional resource dependencies based on these attributes is not
recommended, as Terraform diffs will be continually generated to keep
up with the live changes.
* When a Spot Instance Request is deleted/canceled, an attempt is made
to terminate the last-known attached spot instance. Race conditions
dictate that this attempt cannot guarantee that the associated spot
instance is terminated immediately.
Implementation notes:
* This version of aws_spot_instance_request borrows a lot of common
code from aws_instance.
* In order to facilitate borrowing, we introduce `awsInstanceOpts`, an
internal representation of instance details that's meant to be shared
between resources. The goal here would be to refactor ASG Launch
Configurations to use the same struct.
* The new aws_spot_instance_request acc. test is passing.
* All aws_instance acc. tests remain passing.
2015-06-05 17:12:09 +02:00
|
|
|
}
|
2015-08-06 21:22:10 +02:00
|
|
|
|
2017-02-03 00:57:50 +01:00
|
|
|
func testAccAWSSpotInstanceRequestConfig_withBlockDuration(rInt int) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "aws_key_pair" "debugging" {
|
|
|
|
key_name = "tmp-key-%d"
|
|
|
|
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 phodgson@thoughtworks.com"
|
|
|
|
}
|
2015-11-26 12:56:04 +01:00
|
|
|
|
2017-02-03 00:57:50 +01:00
|
|
|
resource "aws_spot_instance_request" "foo" {
|
|
|
|
ami = "ami-4fccb37f"
|
|
|
|
instance_type = "m1.small"
|
|
|
|
key_name = "${aws_key_pair.debugging.key_name}"
|
2015-11-26 12:56:04 +01:00
|
|
|
|
2017-02-03 00:57:50 +01:00
|
|
|
// base price is $0.044 hourly, so bidding above that should theoretically
|
|
|
|
// always fulfill
|
|
|
|
spot_price = "0.05"
|
2015-11-26 12:56:04 +01:00
|
|
|
|
2017-02-03 00:57:50 +01:00
|
|
|
// we wait for fulfillment because we want to inspect the launched instance
|
|
|
|
// and verify termination behavior
|
|
|
|
wait_for_fulfillment = true
|
2015-11-26 12:56:04 +01:00
|
|
|
|
2017-02-03 00:57:50 +01:00
|
|
|
block_duration_minutes = 60
|
2015-11-26 12:56:04 +01:00
|
|
|
|
2017-02-03 00:57:50 +01:00
|
|
|
tags {
|
|
|
|
Name = "terraform-test"
|
|
|
|
}
|
|
|
|
}`, rInt)
|
2015-11-26 12:56:04 +01:00
|
|
|
}
|
|
|
|
|
2017-02-03 00:57:50 +01:00
|
|
|
func testAccAWSSpotInstanceRequestConfigVPC(rInt int) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "aws_vpc" "foo_VPC" {
|
|
|
|
cidr_block = "10.1.0.0/16"
|
|
|
|
}
|
2015-08-06 21:22:10 +02:00
|
|
|
|
2017-02-03 00:57:50 +01:00
|
|
|
resource "aws_subnet" "foo_VPC" {
|
|
|
|
cidr_block = "10.1.1.0/24"
|
|
|
|
vpc_id = "${aws_vpc.foo_VPC.id}"
|
|
|
|
}
|
2015-08-06 21:22:10 +02:00
|
|
|
|
2017-02-03 00:57:50 +01:00
|
|
|
resource "aws_key_pair" "debugging" {
|
|
|
|
key_name = "tmp-key-%d"
|
|
|
|
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 phodgson@thoughtworks.com"
|
|
|
|
}
|
2015-08-06 21:22:10 +02:00
|
|
|
|
2017-02-03 00:57:50 +01:00
|
|
|
resource "aws_spot_instance_request" "foo_VPC" {
|
|
|
|
ami = "ami-4fccb37f"
|
|
|
|
instance_type = "m1.small"
|
|
|
|
key_name = "${aws_key_pair.debugging.key_name}"
|
2015-08-06 21:22:10 +02:00
|
|
|
|
2017-02-03 00:57:50 +01:00
|
|
|
// base price is $0.044 hourly, so bidding above that should theoretically
|
|
|
|
// always fulfill
|
|
|
|
spot_price = "0.05"
|
2015-08-06 21:22:10 +02:00
|
|
|
|
2017-02-03 00:57:50 +01:00
|
|
|
// VPC settings
|
|
|
|
subnet_id = "${aws_subnet.foo_VPC.id}"
|
2015-08-06 21:22:10 +02:00
|
|
|
|
2017-02-03 00:57:50 +01:00
|
|
|
// we wait for fulfillment because we want to inspect the launched instance
|
|
|
|
// and verify termination behavior
|
|
|
|
wait_for_fulfillment = true
|
2015-08-06 21:22:10 +02:00
|
|
|
|
2017-02-03 00:57:50 +01:00
|
|
|
tags {
|
|
|
|
Name = "terraform-test-VPC"
|
|
|
|
}
|
|
|
|
}`, rInt)
|
2015-11-16 22:11:44 +01:00
|
|
|
}
|
|
|
|
|
2017-02-03 00:57:50 +01:00
|
|
|
func testAccAWSSpotInstanceRequestConfig_SubnetAndSG(rInt int) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "aws_spot_instance_request" "foo" {
|
|
|
|
ami = "ami-4fccb37f"
|
|
|
|
instance_type = "m1.small"
|
|
|
|
spot_price = "0.05"
|
|
|
|
wait_for_fulfillment = true
|
|
|
|
subnet_id = "${aws_subnet.tf_test_subnet.id}"
|
|
|
|
vpc_security_group_ids = ["${aws_security_group.tf_test_sg_ssh.id}"]
|
|
|
|
associate_public_ip_address = true
|
|
|
|
}
|
2015-11-16 22:11:44 +01:00
|
|
|
|
2017-02-03 00:57:50 +01:00
|
|
|
resource "aws_vpc" "default" {
|
|
|
|
cidr_block = "10.0.0.0/16"
|
|
|
|
enable_dns_hostnames = true
|
2015-11-16 22:11:44 +01:00
|
|
|
|
2017-02-03 00:57:50 +01:00
|
|
|
tags {
|
|
|
|
Name = "tf_test_vpc"
|
|
|
|
}
|
|
|
|
}
|
2015-11-16 22:11:44 +01:00
|
|
|
|
2017-02-03 00:57:50 +01:00
|
|
|
resource "aws_subnet" "tf_test_subnet" {
|
|
|
|
vpc_id = "${aws_vpc.default.id}"
|
|
|
|
cidr_block = "10.0.0.0/24"
|
|
|
|
map_public_ip_on_launch = true
|
|
|
|
|
|
|
|
tags {
|
|
|
|
Name = "tf_test_subnet-%d"
|
|
|
|
}
|
|
|
|
}
|
2015-11-16 22:11:44 +01:00
|
|
|
|
2017-02-03 00:57:50 +01:00
|
|
|
resource "aws_security_group" "tf_test_sg_ssh" {
|
|
|
|
name = "tf_test_sg_ssh-%d"
|
|
|
|
description = "tf_test_sg_ssh"
|
|
|
|
vpc_id = "${aws_vpc.default.id}"
|
2015-11-16 22:11:44 +01:00
|
|
|
|
2017-02-03 00:57:50 +01:00
|
|
|
tags {
|
|
|
|
Name = "tf_test_sg_ssh-%d"
|
|
|
|
}
|
|
|
|
}`, rInt, rInt, rInt)
|
2015-11-16 22:11:44 +01:00
|
|
|
}
|