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

aws_spot_fleet_request: gp3 volume scalable throughput #16652

Merged
Merged
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
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