|
|
|
|
@ -13,6 +13,11 @@ import (
|
|
|
|
|
"github.com/hashicorp/packer/packer-plugin-sdk/template/interpolate"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
minIops = 100
|
|
|
|
|
maxIops = 64000
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// These will be attached when launching your instance. Your
|
|
|
|
|
// options here may vary depending on the type of VM you use.
|
|
|
|
|
//
|
|
|
|
|
@ -154,6 +159,11 @@ func (blockDevice BlockDevice) BuildEC2BlockDeviceMapping() *ec2.BlockDeviceMapp
|
|
|
|
|
return mapping
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var iopsRatios = map[string]int64{
|
|
|
|
|
"io1": 50,
|
|
|
|
|
"io2": 500,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *BlockDevice) Prepare(ctx *interpolate.Context) error {
|
|
|
|
|
if b.DeviceName == "" {
|
|
|
|
|
return fmt.Errorf("The `device_name` must be specified " +
|
|
|
|
|
@ -166,6 +176,18 @@ func (b *BlockDevice) Prepare(ctx *interpolate.Context) error {
|
|
|
|
|
"true` when setting a kms_key_id.", b.DeviceName)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ratio, ok := iopsRatios[b.VolumeType]; b.VolumeSize != 0 && ok {
|
|
|
|
|
if 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 {
|
|
|
|
|
return fmt.Errorf("IOPS must be between %d and %d for device %s",
|
|
|
|
|
minIops, maxIops, b.DeviceName)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err := interpolate.RenderInterface(&b, ctx)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|