2019-05-31 14:27:41 +02:00
|
|
|
//go:generate struct-markdown
|
|
|
|
|
|
2016-10-31 16:44:41 -05:00
|
|
|
package ebsvolume
|
|
|
|
|
|
|
|
|
|
import (
|
2019-06-18 16:02:08 +02:00
|
|
|
"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 {
|
2019-06-18 16:02:08 +02:00
|
|
|
awscommon.BlockDevice `mapstructure:",squash"`
|
2020-04-16 15:37:22 +02:00
|
|
|
// Key/value pair tags to apply to the volume. These are retained after the builder
|
2020-04-01 18:54:21 -04:00
|
|
|
// 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
|
2020-04-16 15:37:22 +02:00
|
|
|
// containing a `key` and a `value` field. In HCL2 mode the
|
2020-04-01 18:54:21 -04:00
|
|
|
// [`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.
|
2020-04-16 15:37:22 +02:00
|
|
|
Tag hcl2template.KeyValues `mapstructure:"tag" required:"false"`
|
2016-10-31 16:44:41 -05:00
|
|
|
}
|
|
|
|
|
|
2019-06-18 16:02:08 +02:00
|
|
|
type BlockDevices []BlockDevice
|
2017-01-26 21:10:25 +01:00
|
|
|
|
2019-06-18 16:02:08 +02:00
|
|
|
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
|
|
|
|
2019-06-18 16:02:08 +02:00
|
|
|
for _, block := range bds {
|
2020-03-16 12:26:03 +01:00
|
|
|
|
2020-03-16 15:46:08 +01:00
|
|
|
errs = append(errs, block.Tag.CopyOn(&block.Tags)...)
|
2020-03-16 12:26:03 +01:00
|
|
|
|
2019-06-18 16:02:08 +02:00
|
|
|
if err := block.Prepare(ctx); err != nil {
|
|
|
|
|
errs = append(errs, err)
|
2017-01-26 21:10:25 +01:00
|
|
|
}
|
2020-03-16 12:26:03 +01:00
|
|
|
|
2019-06-18 16:02:08 +02:00
|
|
|
}
|
|
|
|
|
return errs
|
|
|
|
|
}
|