feature: add root block device config to bsusurrogate config struct

This commit is contained in:
Marin Salinas 2019-01-29 11:28:11 -06:00 committed by Megan Marsh
parent f6372e8ac6
commit 837aada415
2 changed files with 50 additions and 1 deletions

View File

@ -20,7 +20,10 @@ type Config struct {
osccommon.RunConfig `mapstructure:",squash"`
osccommon.BlockDevices `mapstructure:",squash"`
osccommon.OMIConfig `mapstructure:",squash"`
ctx interpolate.Context
RootDevice RootBlockDevice `mapstructure:"ami_root_device"`
ctx interpolate.Context
}
type Builder struct {

View File

@ -0,0 +1,46 @@
package bsusurrogate
import (
"errors"
"github.com/hashicorp/packer/template/interpolate"
)
type RootBlockDevice struct {
SourceDeviceName string `mapstructure:"source_device_name"`
DeviceName string `mapstructure:"device_name"`
DeleteOnVmDeletion bool `mapstructure:"delete_on_vm_deletion"`
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
}