2016-12-30 16:21:23 -05:00
|
|
|
package ebssurrogate
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2018-01-22 20:21:10 -05:00
|
|
|
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/template/interpolate"
|
2016-12-30 16:21:23 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type RootBlockDevice struct {
|
|
|
|
SourceDeviceName string `mapstructure:"source_device_name"`
|
|
|
|
DeviceName string `mapstructure:"device_name"`
|
|
|
|
DeleteOnTermination bool `mapstructure:"delete_on_termination"`
|
|
|
|
IOPS int64 `mapstructure:"iops"`
|
|
|
|
VolumeType string `mapstructure:"volume_type"`
|
|
|
|
VolumeSize int64 `mapstructure:"volume_size"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *RootBlockDevice) Prepare(ctx *interpolate.Context) []error {
|
|
|
|
var errs []error
|
|
|
|
|
|
|
|
if c.SourceDeviceName == "" {
|
|
|
|
errs = append(errs, errors.New("source_device_name for the root_device must be specified"))
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.DeviceName == "" {
|
|
|
|
errs = append(errs, errors.New("device_name for the root_device must be specified"))
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.VolumeType == "gp2" && c.IOPS != 0 {
|
|
|
|
errs = append(errs, errors.New("iops may not be specified for a gp2 volume"))
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.IOPS < 0 {
|
|
|
|
errs = append(errs, errors.New("iops must be greater than 0"))
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.VolumeSize < 0 {
|
|
|
|
errs = append(errs, errors.New("volume_size must be greater than 0"))
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(errs) > 0 {
|
|
|
|
return errs
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|