2019-05-31 08:27:41 -04:00
|
|
|
//go:generate struct-markdown
|
|
|
|
|
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 {
|
2019-06-06 10:29:25 -04:00
|
|
|
SourceDeviceName string `mapstructure:"source_device_name"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// The device name exposed to the instance (for
|
2019-06-06 10:29:25 -04:00
|
|
|
// example, /dev/sdh or xvdh). Required for every device in the block
|
|
|
|
// device mapping.
|
|
|
|
DeviceName string `mapstructure:"device_name" required:"false"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// Indicates whether the EBS volume is
|
2019-06-06 10:29:25 -04:00
|
|
|
// deleted on instance termination. Default false. NOTE: If this
|
|
|
|
// value is not explicitly set to true and volumes are not cleaned up by
|
|
|
|
// an alternative method, additional volumes will accumulate after every
|
|
|
|
// build.
|
|
|
|
DeleteOnTermination bool `mapstructure:"delete_on_termination" required:"false"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// The number of I/O operations per second (IOPS) that
|
2019-06-06 10:29:25 -04:00
|
|
|
// the volume supports. See the documentation on
|
|
|
|
// IOPs
|
|
|
|
// for more information
|
|
|
|
IOPS int64 `mapstructure:"iops" required:"false"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// The volume type. gp2 for General Purpose
|
2019-06-06 10:29:25 -04:00
|
|
|
// (SSD) volumes, io1 for Provisioned IOPS (SSD) volumes, st1 for
|
|
|
|
// Throughput Optimized HDD, sc1 for Cold HDD, and standard for
|
|
|
|
// Magnetic volumes.
|
|
|
|
VolumeType string `mapstructure:"volume_type" required:"false"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// The size of the volume, in GiB. Required if
|
2019-06-06 10:29:25 -04:00
|
|
|
// not specifying a snapshot_id.
|
|
|
|
VolumeSize int64 `mapstructure:"volume_size" required:"false"`
|
2016-12-30 16:21:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|