github.com/Hashicorp/packer@v1.3.2/builder/amazon/ebssurrogate/root_block_device.go (about)

     1  package ebssurrogate
     2  
     3  import (
     4  	"errors"
     5  
     6  	"github.com/hashicorp/packer/template/interpolate"
     7  )
     8  
     9  type RootBlockDevice struct {
    10  	SourceDeviceName    string `mapstructure:"source_device_name"`
    11  	DeviceName          string `mapstructure:"device_name"`
    12  	DeleteOnTermination bool   `mapstructure:"delete_on_termination"`
    13  	IOPS                int64  `mapstructure:"iops"`
    14  	VolumeType          string `mapstructure:"volume_type"`
    15  	VolumeSize          int64  `mapstructure:"volume_size"`
    16  }
    17  
    18  func (c *RootBlockDevice) Prepare(ctx *interpolate.Context) []error {
    19  	var errs []error
    20  
    21  	if c.SourceDeviceName == "" {
    22  		errs = append(errs, errors.New("source_device_name for the root_device must be specified"))
    23  	}
    24  
    25  	if c.DeviceName == "" {
    26  		errs = append(errs, errors.New("device_name for the root_device must be specified"))
    27  	}
    28  
    29  	if c.VolumeType == "gp2" && c.IOPS != 0 {
    30  		errs = append(errs, errors.New("iops may not be specified for a gp2 volume"))
    31  	}
    32  
    33  	if c.IOPS < 0 {
    34  		errs = append(errs, errors.New("iops must be greater than 0"))
    35  	}
    36  
    37  	if c.VolumeSize < 0 {
    38  		errs = append(errs, errors.New("volume_size must be greater than 0"))
    39  	}
    40  
    41  	if len(errs) > 0 {
    42  		return errs
    43  	}
    44  
    45  	return nil
    46  }