read iops and throughput as pointers so we can test for the nil case;… (#10518)

This commit is contained in:
Megan Marsh 2021-01-25 01:49:37 -08:00 committed by GitHub
parent 48a31d1b6a
commit 3242b7ee10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 35 deletions

View File

@ -76,7 +76,7 @@ type BlockDevice struct {
// See the documentation on
// [IOPs](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_EbsBlockDevice.html)
// for more information
IOPS int64 `mapstructure:"iops" required:"false"`
IOPS *int64 `mapstructure:"iops" required:"false"`
// Suppresses the specified device included in the block device mapping of
// the AMI.
NoDevice bool `mapstructure:"no_device" required:"false"`
@ -86,7 +86,7 @@ type BlockDevice struct {
// See the documentation on
// [Throughput](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_EbsBlockDevice.html)
// for more information
Throughput int64 `mapstructure:"throughput" required:"false"`
Throughput *int64 `mapstructure:"throughput" required:"false"`
// The virtual device name. See the documentation on Block Device Mapping
// for more information.
VirtualName string `mapstructure:"virtual_name" required:"false"`
@ -150,12 +150,12 @@ func (blockDevice BlockDevice) BuildEC2BlockDeviceMapping() *ec2.BlockDeviceMapp
switch blockDevice.VolumeType {
case "io1", "io2", "gp3":
ebsBlockDevice.Iops = aws.Int64(blockDevice.IOPS)
ebsBlockDevice.Iops = blockDevice.IOPS
}
// Throughput is only valid for gp3 types
if blockDevice.VolumeType == "gp3" {
ebsBlockDevice.Throughput = aws.Int64(blockDevice.Throughput)
ebsBlockDevice.Throughput = blockDevice.Throughput
}
// You cannot specify Encrypted if you specify a Snapshot ID
@ -191,28 +191,28 @@ func (b *BlockDevice) Prepare(ctx *interpolate.Context) error {
}
if ratio, ok := iopsRatios[b.VolumeType]; b.VolumeSize != 0 && ok {
if b.IOPS/b.VolumeSize > ratio {
if b.IOPS != nil && (*b.IOPS/b.VolumeSize > ratio) {
return fmt.Errorf("%s: the maximum ratio of provisioned IOPS to requested volume size "+
"(in GiB) is %v:1 for %s volumes", b.DeviceName, ratio, b.VolumeType)
}
if b.IOPS < minIops || b.IOPS > maxIops {
if b.IOPS != nil && (*b.IOPS < minIops || *b.IOPS > maxIops) {
return fmt.Errorf("IOPS must be between %d and %d for device %s",
minIops, maxIops, b.DeviceName)
}
}
if b.VolumeType == "gp3" {
if b.Throughput < minThroughput || b.Throughput > maxThroughput {
if b.Throughput != nil && (*b.Throughput < minThroughput || *b.Throughput > maxThroughput) {
return fmt.Errorf("Throughput must be between %d and %d for device %s",
minThroughput, maxThroughput, b.DeviceName)
}
if b.IOPS < minIopsGp3 || b.IOPS > maxIopsGp3 {
if b.IOPS != nil && (*b.IOPS < minIopsGp3 || *b.IOPS > maxIopsGp3) {
return fmt.Errorf("IOPS must be between %d and %d for device %s",
minIopsGp3, maxIopsGp3, b.DeviceName)
}
} else if b.Throughput > 0 {
} else if b.Throughput != nil {
return fmt.Errorf("Throughput is not available for device %s",
b.DeviceName)
}

View File

@ -54,7 +54,7 @@ func TestBlockDevice(t *testing.T) {
VolumeType: "io1",
VolumeSize: 8,
DeleteOnTermination: true,
IOPS: 1000,
IOPS: aws.Int64(1000),
},
Result: &ec2.BlockDeviceMapping{
@ -73,7 +73,7 @@ func TestBlockDevice(t *testing.T) {
VolumeType: "io2",
VolumeSize: 8,
DeleteOnTermination: true,
IOPS: 1000,
IOPS: aws.Int64(1000),
},
Result: &ec2.BlockDeviceMapping{
@ -168,8 +168,8 @@ func TestBlockDevice(t *testing.T) {
DeviceName: "/dev/sdb",
VolumeType: "gp3",
VolumeSize: 8,
Throughput: 125,
IOPS: 3000,
Throughput: aws.Int64(125),
IOPS: aws.Int64(3000),
DeleteOnTermination: true,
Encrypted: config.TriTrue,
},
@ -219,7 +219,7 @@ func TestIOPSValidation(t *testing.T) {
device: BlockDevice{
DeviceName: "/dev/sdb",
VolumeType: "io1",
IOPS: 1000,
IOPS: aws.Int64(1000),
},
ok: true,
},
@ -227,7 +227,7 @@ func TestIOPSValidation(t *testing.T) {
device: BlockDevice{
DeviceName: "/dev/sdb",
VolumeType: "io2",
IOPS: 1000,
IOPS: aws.Int64(1000),
},
ok: true,
},
@ -237,7 +237,7 @@ func TestIOPSValidation(t *testing.T) {
DeviceName: "/dev/sdb",
VolumeType: "io1",
VolumeSize: 50,
IOPS: 1000,
IOPS: aws.Int64(1000),
},
ok: true,
},
@ -246,7 +246,7 @@ func TestIOPSValidation(t *testing.T) {
DeviceName: "/dev/sdb",
VolumeType: "io2",
VolumeSize: 100,
IOPS: 1000,
IOPS: aws.Int64(1000),
},
ok: true,
},
@ -256,7 +256,7 @@ func TestIOPSValidation(t *testing.T) {
DeviceName: "/dev/sdb",
VolumeType: "io1",
VolumeSize: 10,
IOPS: 2000,
IOPS: aws.Int64(2000),
},
ok: false,
msg: "/dev/sdb: the maximum ratio of provisioned IOPS to requested volume size (in GiB) is 50:1 for io1 volumes",
@ -266,7 +266,7 @@ func TestIOPSValidation(t *testing.T) {
DeviceName: "/dev/sdb",
VolumeType: "io2",
VolumeSize: 50,
IOPS: 30000,
IOPS: aws.Int64(30000),
},
ok: false,
msg: "/dev/sdb: the maximum ratio of provisioned IOPS to requested volume size (in GiB) is 500:1 for io2 volumes",
@ -277,7 +277,7 @@ func TestIOPSValidation(t *testing.T) {
DeviceName: "/dev/sdb",
VolumeType: "io2",
VolumeSize: 500,
IOPS: 99999,
IOPS: aws.Int64(99999),
},
ok: false,
msg: "IOPS must be between 100 and 64000 for device /dev/sdb",
@ -288,7 +288,7 @@ func TestIOPSValidation(t *testing.T) {
DeviceName: "/dev/sdb",
VolumeType: "io2",
VolumeSize: 50,
IOPS: 10,
IOPS: aws.Int64(10),
},
ok: false,
msg: "IOPS must be between 100 and 64000 for device /dev/sdb",
@ -299,8 +299,8 @@ func TestIOPSValidation(t *testing.T) {
DeviceName: "/dev/sdb",
VolumeType: "gp3",
VolumeSize: 50,
Throughput: 125,
IOPS: 99999,
Throughput: aws.Int64(125),
IOPS: aws.Int64(99999),
},
ok: false,
msg: "IOPS must be between 3000 and 16000 for device /dev/sdb",
@ -311,8 +311,8 @@ func TestIOPSValidation(t *testing.T) {
DeviceName: "/dev/sdb",
VolumeType: "gp3",
VolumeSize: 50,
Throughput: 125,
IOPS: 10,
Throughput: aws.Int64(125),
IOPS: aws.Int64(10),
},
ok: false,
msg: "IOPS must be between 3000 and 16000 for device /dev/sdb",
@ -346,8 +346,8 @@ func TestThroughputValidation(t *testing.T) {
device: BlockDevice{
DeviceName: "/dev/sdb",
VolumeType: "gp3",
Throughput: 125,
IOPS: 3000,
Throughput: aws.Int64(125),
IOPS: aws.Int64(3000),
},
ok: true,
},
@ -355,8 +355,8 @@ func TestThroughputValidation(t *testing.T) {
device: BlockDevice{
DeviceName: "/dev/sdb",
VolumeType: "gp3",
Throughput: 1000,
IOPS: 3000,
Throughput: aws.Int64(1000),
IOPS: aws.Int64(3000),
},
ok: true,
},
@ -365,8 +365,8 @@ func TestThroughputValidation(t *testing.T) {
device: BlockDevice{
DeviceName: "/dev/sdb",
VolumeType: "gp3",
Throughput: 1001,
IOPS: 3000,
Throughput: aws.Int64(1001),
IOPS: aws.Int64(3000),
},
ok: false,
msg: "Throughput must be between 125 and 1000 for device /dev/sdb",
@ -376,8 +376,8 @@ func TestThroughputValidation(t *testing.T) {
device: BlockDevice{
DeviceName: "/dev/sdb",
VolumeType: "gp3",
Throughput: 124,
IOPS: 3000,
Throughput: aws.Int64(124),
IOPS: aws.Int64(3000),
},
ok: false,
msg: "Throughput must be between 125 and 1000 for device /dev/sdb",

View File

@ -13,7 +13,7 @@
false will result in an unencrypted device, and true will result in an
encrypted one.
- `iops` (int64) - The number of I/O operations per second (IOPS) that the volume supports.
- `iops` (\*int64) - The number of I/O operations per second (IOPS) that the volume supports.
See the documentation on
[IOPs](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_EbsBlockDevice.html)
for more information
@ -23,7 +23,7 @@
- `snapshot_id` (string) - The ID of the snapshot.
- `throughput` (int64) - The throughput for gp3 volumes, only valid for gp3 types
- `throughput` (\*int64) - The throughput for gp3 volumes, only valid for gp3 types
See the documentation on
[Throughput](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_EbsBlockDevice.html)
for more information