Files
Packer-Cn/builder/amazon/ebsvolume/block_device.go
T

49 lines
1.5 KiB
Go
Raw Normal View History

//go:generate struct-markdown
2016-10-31 16:44:41 -05:00
package ebsvolume
import (
"github.com/aws/aws-sdk-go/service/ec2"
2017-04-04 13:39:01 -07:00
awscommon "github.com/hashicorp/packer/builder/amazon/common"
2020-03-13 18:04:48 +01:00
"github.com/hashicorp/packer/hcl2template"
2017-04-04 13:39:01 -07:00
"github.com/hashicorp/packer/template/interpolate"
2016-10-31 16:44:41 -05:00
)
type BlockDevice struct {
awscommon.BlockDevice `mapstructure:",squash"`
// Key/value pair tags to apply to the volume. These are retained after the builder
// completes. This is a [template engine](/docs/templates/engine), see
2019-08-27 09:21:29 +02:00
// [Build template data](#build-template-data) for more information.
2020-03-16 17:47:44 +01:00
Tags map[string]string `mapstructure:"tags" required:"false"`
2020-03-16 12:19:34 +01:00
// Same as [`tags`](#tags) but defined as a singular repeatable block
// containing a `key` and a `value` field. In HCL2 mode the
// [`dynamic_block`](/docs/configuration/from-1.5/expressions#dynamic-blocks)
2020-03-13 18:04:48 +01:00
// will allow you to create those programatically.
Tag hcl2template.KeyValues `mapstructure:"tag" required:"false"`
2016-10-31 16:44:41 -05:00
}
type BlockDevices []BlockDevice
func (bds BlockDevices) BuildEC2BlockDeviceMappings() []*ec2.BlockDeviceMapping {
var blockDevices []*ec2.BlockDeviceMapping
for _, blockDevice := range bds {
blockDevices = append(blockDevices, blockDevice.BuildEC2BlockDeviceMapping())
}
return blockDevices
}
func (bds BlockDevices) Prepare(ctx *interpolate.Context) (errs []error) {
2020-03-16 12:26:03 +01:00
for _, block := range bds {
2020-03-16 12:26:03 +01:00
errs = append(errs, block.Tag.CopyOn(&block.Tags)...)
2020-03-16 12:26:03 +01:00
if err := block.Prepare(ctx); err != nil {
errs = append(errs, err)
}
2020-03-16 12:26:03 +01:00
}
return errs
}