cb3699a584
Documentation for ebssurrogate states that all of the devices in `launch_block_device_mappings` are snapshotted and included in the image. In fact, only the device that was designated as the root device was snapshotted. This patch modifies the builder to create snapshots of all the devices and include them in the image. This allows creating images with separate filesystems preconfigured, rather than having to add volumes to `ami_block_device_mappings` and configure them after boot.
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package ebssurrogate
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/hashicorp/packer/template/interpolate"
|
|
)
|
|
|
|
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
|
|
}
|