builder/amazon: string fields on device mappings can use variables
This commit is contained in:
parent
41372c4bfa
commit
5db91c84bf
|
@ -30,6 +30,7 @@ IMPROVEMENTS:
|
||||||
set with the `token` configuration. [GH-1236]
|
set with the `token` configuration. [GH-1236]
|
||||||
* builder/amazon/all: Can force SSH on the private IP address with
|
* builder/amazon/all: Can force SSH on the private IP address with
|
||||||
`ssh_private_ip`. [GH-1229]
|
`ssh_private_ip`. [GH-1229]
|
||||||
|
* builder/amazon/all: String fields in device mappings can use variables. [GH-1090]
|
||||||
* builder/amazon-instance: EBS AMIs can be used as a source. [GH-1453]
|
* builder/amazon-instance: EBS AMIs can be used as a source. [GH-1453]
|
||||||
* builder/digitalocean: Can set API URL endpoint. [GH-1448]
|
* builder/digitalocean: Can set API URL endpoint. [GH-1448]
|
||||||
* builder/digitalocean: Region supports variables. [GH-1452]
|
* builder/digitalocean: Region supports variables. [GH-1452]
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/mitchellh/goamz/ec2"
|
"github.com/mitchellh/goamz/ec2"
|
||||||
|
"github.com/mitchellh/packer/packer"
|
||||||
)
|
)
|
||||||
|
|
||||||
// BlockDevice
|
// BlockDevice
|
||||||
|
@ -41,6 +44,51 @@ func buildBlockDevices(b []BlockDevice) []ec2.BlockDeviceMapping {
|
||||||
return blockDevices
|
return blockDevices
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *BlockDevices) Prepare(t *packer.ConfigTemplate) []error {
|
||||||
|
if t == nil {
|
||||||
|
var err error
|
||||||
|
t, err = packer.NewConfigTemplate()
|
||||||
|
if err != nil {
|
||||||
|
return []error{err}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lists := map[string][]BlockDevice{
|
||||||
|
"ami_block_device_mappings": b.AMIMappings,
|
||||||
|
"launch_block_device_mappings": b.LaunchMappings,
|
||||||
|
}
|
||||||
|
|
||||||
|
var errs []error
|
||||||
|
for outer, bds := range lists {
|
||||||
|
for i, bd := range bds {
|
||||||
|
templates := map[string]*string{
|
||||||
|
"device_name": &bd.DeviceName,
|
||||||
|
"snapshot_id": &bd.SnapshotId,
|
||||||
|
"virtual_name": &bd.VirtualName,
|
||||||
|
"volume_type": &bd.VolumeType,
|
||||||
|
}
|
||||||
|
|
||||||
|
errs := make([]error, 0)
|
||||||
|
for n, ptr := range templates {
|
||||||
|
var err error
|
||||||
|
*ptr, err = t.Process(*ptr, nil)
|
||||||
|
if err != nil {
|
||||||
|
errs = append(
|
||||||
|
errs, fmt.Errorf(
|
||||||
|
"Error processing %s[%d].%s: %s",
|
||||||
|
outer, i, n, err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(errs) > 0 {
|
||||||
|
return errs
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (b *BlockDevices) BuildAMIDevices() []ec2.BlockDeviceMapping {
|
func (b *BlockDevices) BuildAMIDevices() []ec2.BlockDeviceMapping {
|
||||||
return buildBlockDevices(b.AMIMappings)
|
return buildBlockDevices(b.AMIMappings)
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
|
||||||
// Accumulate any errors
|
// Accumulate any errors
|
||||||
errs := common.CheckUnusedConfig(md)
|
errs := common.CheckUnusedConfig(md)
|
||||||
errs = packer.MultiErrorAppend(errs, b.config.AccessConfig.Prepare(b.config.tpl)...)
|
errs = packer.MultiErrorAppend(errs, b.config.AccessConfig.Prepare(b.config.tpl)...)
|
||||||
|
errs = packer.MultiErrorAppend(errs, b.config.BlockDevices.Prepare(b.config.tpl)...)
|
||||||
errs = packer.MultiErrorAppend(errs, b.config.AMIConfig.Prepare(b.config.tpl)...)
|
errs = packer.MultiErrorAppend(errs, b.config.AMIConfig.Prepare(b.config.tpl)...)
|
||||||
errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare(b.config.tpl)...)
|
errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare(b.config.tpl)...)
|
||||||
|
|
||||||
|
|
|
@ -99,6 +99,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
|
||||||
// Accumulate any errors
|
// Accumulate any errors
|
||||||
errs := common.CheckUnusedConfig(md)
|
errs := common.CheckUnusedConfig(md)
|
||||||
errs = packer.MultiErrorAppend(errs, b.config.AccessConfig.Prepare(b.config.tpl)...)
|
errs = packer.MultiErrorAppend(errs, b.config.AccessConfig.Prepare(b.config.tpl)...)
|
||||||
|
errs = packer.MultiErrorAppend(errs, b.config.BlockDevices.Prepare(b.config.tpl)...)
|
||||||
errs = packer.MultiErrorAppend(errs, b.config.AMIConfig.Prepare(b.config.tpl)...)
|
errs = packer.MultiErrorAppend(errs, b.config.AMIConfig.Prepare(b.config.tpl)...)
|
||||||
errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare(b.config.tpl)...)
|
errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare(b.config.tpl)...)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue