Skip to content
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

spot_instance_request: fixed network interfaces configuration #4

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions aws/resource_aws_spot_instance_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,14 @@ func resourceAwsSpotInstanceRequestCreate(d *schema.ResourceData, meta interface
SecurityGroups: instanceOpts.SecurityGroups,
SubnetId: instanceOpts.SubnetID,
UserData: instanceOpts.UserData64,
NetworkInterfaces: instanceOpts.NetworkInterfaces,
},
}

if v, ok := d.GetOk("block_duration_minutes"); ok {
spotOpts.BlockDurationMinutes = aws.Int64(int64(v.(int)))
}

// If the instance is configured with a Network Interface (a subnet, has
// public IP, etc), then the instanceOpts.SecurityGroupIds and SubnetId will
// be nil
if len(instanceOpts.NetworkInterfaces) > 0 {
spotOpts.LaunchSpecification.SecurityGroupIds = instanceOpts.NetworkInterfaces[0].Groups
spotOpts.LaunchSpecification.SubnetId = instanceOpts.NetworkInterfaces[0].SubnetId
Copy link
Member

@radeksimko radeksimko Jun 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason we can't just add this line here?

spotOpts.LaunchSpecification.NetworkInterfaces = instanceOpts.NetworkInterfaces

We don't seem to have a test covering the case in the comment here, but I'd be worried that removing the logic may break some unrelated edge cases... 🤔

}

// Make the spot instance request
log.Printf("[DEBUG] Requesting spot bid opts: %s", spotOpts)

Expand Down
8 changes: 5 additions & 3 deletions aws/resource_aws_spot_instance_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestAccAWSSpotInstanceRequest_vpc(t *testing.T) {
})
}

func TestAccAWSSpotInstanceRequest_SubnetAndSG(t *testing.T) {
func TestAccAWSSpotInstanceRequest_SubnetAndSGAndPublicIpAddress(t *testing.T) {
var sir ec2.SpotInstanceRequest
rInt := acctest.RandInt()

Expand All @@ -103,11 +103,13 @@ func TestAccAWSSpotInstanceRequest_SubnetAndSG(t *testing.T) {
CheckDestroy: testAccCheckAWSSpotInstanceRequestDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSSpotInstanceRequestConfig_SubnetAndSG(rInt),
Config: testAccAWSSpotInstanceRequestConfig_SubnetAndSGAndPublicIpAddress(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSpotInstanceRequestExists(
"aws_spot_instance_request.foo", &sir),
testAccCheckAWSSpotInstanceRequest_InstanceAttributes(&sir, rInt),
resource.TestCheckResourceAttr(
"aws_spot_instance_request.foo", "associate_public_ip_address", "true"),
),
},
},
Expand Down Expand Up @@ -384,7 +386,7 @@ func testAccAWSSpotInstanceRequestConfigVPC(rInt int) string {
}`, rInt)
}

func testAccAWSSpotInstanceRequestConfig_SubnetAndSG(rInt int) string {
func testAccAWSSpotInstanceRequestConfig_SubnetAndSGAndPublicIpAddress(rInt int) string {
return fmt.Sprintf(`
resource "aws_spot_instance_request" "foo" {
ami = "ami-4fccb37f"
Expand Down