Merge pull request #4464 from rickard-von-essen/ebsvolume-interpolate

builder/amazon-ebsvolume: Fix interpolation of block_device
This commit is contained in:
Rickard von Essen 2017-01-26 21:34:19 +01:00 committed by GitHub
commit bc6b4ab8b9
2 changed files with 17 additions and 7 deletions

View File

@ -2,6 +2,7 @@ package ebsvolume
import (
awscommon "github.com/mitchellh/packer/builder/amazon/common"
"github.com/mitchellh/packer/template/interpolate"
)
type BlockDevice struct {
@ -9,15 +10,20 @@ type BlockDevice struct {
Tags map[string]string `mapstructure:"tags"`
}
func commonBlockDevices(mappings []BlockDevice) awscommon.BlockDevices {
func commonBlockDevices(mappings []BlockDevice, ctx *interpolate.Context) (awscommon.BlockDevices, error) {
result := make([]awscommon.BlockDevice, len(mappings))
for i, mapping := range mappings {
result[i] = mapping.BlockDevice
interpolateBlockDev, err := interpolate.RenderInterface(&mapping.BlockDevice, ctx)
if err != nil {
return awscommon.BlockDevices{}, err
}
result[i] = *interpolateBlockDev.(*awscommon.BlockDevice)
}
return awscommon.BlockDevices{
LaunchBlockDevices: awscommon.LaunchBlockDevices{
LaunchMappings: result,
},
}
}, nil
}

View File

@ -28,7 +28,8 @@ type Config struct {
VolumeMappings []BlockDevice `mapstructure:"ebs_volumes"`
AMIEnhancedNetworking bool `mapstructure:"enhanced_networking"`
ctx interpolate.Context
launchBlockDevices awscommon.BlockDevices
ctx interpolate.Context
}
type Builder struct {
@ -57,6 +58,11 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
errs = packer.MultiErrorAppend(errs, b.config.AccessConfig.Prepare(&b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare(&b.config.ctx)...)
b.config.launchBlockDevices, err = commonBlockDevices(b.config.VolumeMappings, &b.config.ctx)
if err != nil {
errs = packer.MultiErrorAppend(errs, err)
}
if errs != nil && len(errs.Errors) > 0 {
return nil, errs
}
@ -96,8 +102,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
state.Put("hook", hook)
state.Put("ui", ui)
launchBlockDevices := commonBlockDevices(b.config.VolumeMappings)
// Build the steps
steps := []multistep.Step{
&awscommon.StepSourceAMIInfo{
@ -132,7 +136,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
AssociatePublicIpAddress: b.config.AssociatePublicIpAddress,
EbsOptimized: b.config.EbsOptimized,
AvailabilityZone: b.config.AvailabilityZone,
BlockDevices: launchBlockDevices,
BlockDevices: b.config.launchBlockDevices,
Tags: b.config.RunTags,
Ctx: b.config.ctx,
InstanceInitiatedShutdownBehavior: b.config.InstanceInitiatedShutdownBehavior,