Skip to content

Commit

Permalink
resource/aws_spot_fleet_request: Add 'throughput' attribute to 'launc…
Browse files Browse the repository at this point in the history
…h_specification.ebs_block_device' and 'launch_specification.root_block_device' configuration blocks. (#16652)

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSSpotFleetRequest_LaunchSpecification_EbsBlockDeviceGp3\|TestAccAWSSpotFleetRequest_LaunchSpecification_RootBlockDeviceGp3'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSSpotFleetRequest_LaunchSpecification_EbsBlockDeviceGp3\|TestAccAWSSpotFleetRequest_LaunchSpecification_RootBlockDeviceGp3 -timeout 120m
=== RUN   TestAccAWSSpotFleetRequest_LaunchSpecification_EbsBlockDeviceGp3
=== PAUSE TestAccAWSSpotFleetRequest_LaunchSpecification_EbsBlockDeviceGp3
=== RUN   TestAccAWSSpotFleetRequest_LaunchSpecification_RootBlockDeviceGp3
=== PAUSE TestAccAWSSpotFleetRequest_LaunchSpecification_RootBlockDeviceGp3
=== CONT  TestAccAWSSpotFleetRequest_LaunchSpecification_EbsBlockDeviceGp3
=== CONT  TestAccAWSSpotFleetRequest_LaunchSpecification_RootBlockDeviceGp3
--- PASS: TestAccAWSSpotFleetRequest_LaunchSpecification_EbsBlockDeviceGp3 (124.58s)
--- PASS: TestAccAWSSpotFleetRequest_LaunchSpecification_RootBlockDeviceGp3 (124.82s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	124.908s
  • Loading branch information
ewbankkit authored Dec 11, 2020
1 parent 00ccbee commit b5f64e1
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 0 deletions.
28 changes: 28 additions & 0 deletions aws/resource_aws_spot_fleet_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ func resourceAwsSpotFleetRequest() *schema.Resource {
Computed: true,
ForceNew: true,
},
"throughput": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ForceNew: true,
},
"volume_size": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -191,6 +197,12 @@ func resourceAwsSpotFleetRequest() *schema.Resource {
Computed: true,
ForceNew: true,
},
"throughput": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ForceNew: true,
},
"volume_size": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -706,6 +718,10 @@ func readSpotFleetBlockDeviceMappingsFromConfig(
ebs.Iops = aws.Int64(int64(v))
}

if v, ok := bd["throughput"].(int); ok && v > 0 {
ebs.Throughput = aws.Int64(int64(v))
}

blockDevices = append(blockDevices, &ec2.BlockDeviceMapping{
DeviceName: aws.String(bd["device_name"].(string)),
Ebs: ebs,
Expand Down Expand Up @@ -755,6 +771,10 @@ func readSpotFleetBlockDeviceMappingsFromConfig(
ebs.Iops = aws.Int64(int64(v))
}

if v, ok := bd["throughput"].(int); ok && v > 0 {
ebs.Throughput = aws.Int64(int64(v))
}

if dn, err := fetchRootDeviceName(d["ami"].(string), conn); err == nil {
if dn == nil {
return nil, fmt.Errorf(
Expand Down Expand Up @@ -1475,6 +1495,10 @@ func ebsBlockDevicesToSet(bdm []*ec2.BlockDeviceMapping, rootDevName *string) *s
m["iops"] = aws.Int64Value(ebs.Iops)
}

if ebs.Throughput != nil {
m["throughput"] = aws.Int64Value(ebs.Throughput)
}

set.Add(m)
}
}
Expand Down Expand Up @@ -1535,6 +1559,10 @@ func rootBlockDeviceToSet(
m["iops"] = aws.Int64Value(val.Ebs.Iops)
}

if val.Ebs.Throughput != nil {
m["throughput"] = aws.Int64Value(val.Ebs.Throughput)
}

set.Add(m)
}
}
Expand Down
128 changes: 128 additions & 0 deletions aws/resource_aws_spot_fleet_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,71 @@ func TestAccAWSSpotFleetRequest_LaunchSpecification_RootBlockDevice_KmsKeyId(t *
})
}

func TestAccAWSSpotFleetRequest_LaunchSpecification_EbsBlockDeviceGp3(t *testing.T) {
var config ec2.SpotFleetRequestConfig
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_spot_fleet_request.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSEc2SpotFleetRequest(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSSpotFleetRequestDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSSpotFleetRequestLaunchSpecificationEbsBlockDeviceGp3(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAWSSpotFleetRequestExists(resourceName, &config),
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "launch_specification.*.ebs_block_device.*", map[string]string{
"device_name": "/dev/xvdcz",
"iops": "4000",
"throughput": "500",
"volume_size": "15",
"volume_type": "gp3",
}),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"wait_for_fulfillment"},
},
},
})
}

func TestAccAWSSpotFleetRequest_LaunchSpecification_RootBlockDeviceGp3(t *testing.T) {
var config ec2.SpotFleetRequestConfig
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_spot_fleet_request.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSEc2SpotFleetRequest(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSSpotFleetRequestDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSSpotFleetRequestLaunchSpecificationRootBlockDeviceGp3(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAWSSpotFleetRequestExists(resourceName, &config),
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "launch_specification.*.root_block_device.*", map[string]string{
"iops": "4000",
"throughput": "500",
"volume_size": "15",
"volume_type": "gp3",
}),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"wait_for_fulfillment"},
},
},
})
}

func TestAccAWSSpotFleetRequest_withTags(t *testing.T) {
var config ec2.SpotFleetRequestConfig
rName := acctest.RandomWithPrefix("tf-acc-test")
Expand Down Expand Up @@ -2358,6 +2423,69 @@ resource "aws_spot_fleet_request" "test" {
`, validUntil, rName)
}

func testAccAWSSpotFleetRequestLaunchSpecificationEbsBlockDeviceGp3(rName string) string {
return composeConfig(
testAccAWSSpotFleetRequestConfigBase(rName),
`
resource "aws_spot_fleet_request" "test" {
iam_fleet_role = aws_iam_role.test.arn
spot_price = "0.05"
target_capacity = 1
terminate_instances_with_expiration = true
wait_for_fulfillment = true
launch_specification {
ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id
instance_type = "t2.micro"
ebs_block_device {
device_name = "/dev/xvda"
volume_type = "gp2"
volume_size = 8
}
ebs_block_device {
device_name = "/dev/xvdcz"
iops = 4000
throughput = 500
volume_size = 15
volume_type = "gp3"
}
}
depends_on = [aws_iam_policy_attachment.test]
}
`)
}

func testAccAWSSpotFleetRequestLaunchSpecificationRootBlockDeviceGp3(rName string) string {
return composeConfig(
testAccAWSSpotFleetRequestConfigBase(rName),
`
resource "aws_spot_fleet_request" "test" {
iam_fleet_role = aws_iam_role.test.arn
spot_price = "0.05"
target_capacity = 1
terminate_instances_with_expiration = true
wait_for_fulfillment = true
launch_specification {
ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id
instance_type = "t2.micro"
root_block_device {
iops = 4000
throughput = 500
volume_size = 15
volume_type = "gp3"
}
}
depends_on = [aws_iam_policy_attachment.test]
}
`)
}

func testAccAWSSpotFleetRequestLaunchSpecificationWithInstanceStoreAmi(rName string, validUntil string) string {
return testAccLatestAmazonLinuxHvmInstanceStoreAmiConfig() +
testAccAWSSpotFleetRequestConfigBase(rName) +
Expand Down

0 comments on commit b5f64e1

Please sign in to comment.