Commit 7ab45f85 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/amazon/ebs: process templates for config

parent e6b7a478
...@@ -14,7 +14,6 @@ import ( ...@@ -14,7 +14,6 @@ import (
"github.com/mitchellh/packer/common" "github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"log" "log"
"text/template"
) )
// The unique ID for this builder // The unique ID for this builder
...@@ -30,6 +29,8 @@ type config struct { ...@@ -30,6 +29,8 @@ type config struct {
// Tags for the AMI // Tags for the AMI
Tags map[string]string Tags map[string]string
tpl *common.Template
} }
type Builder struct { type Builder struct {
...@@ -43,23 +44,45 @@ func (b *Builder) Prepare(raws ...interface{}) error { ...@@ -43,23 +44,45 @@ func (b *Builder) Prepare(raws ...interface{}) error {
return err return err
} }
b.config.tpl, err = common.NewTemplate()
if err != nil {
return err
}
// Accumulate any errors // Accumulate any errors
errs := common.CheckUnusedConfig(md) errs := common.CheckUnusedConfig(md)
errs = packer.MultiErrorAppend(errs, b.config.AccessConfig.Prepare()...) errs = packer.MultiErrorAppend(errs, b.config.AccessConfig.Prepare(b.config.tpl)...)
errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare()...) errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare(b.config.tpl)...)
// Accumulate any errors // Accumulate any errors
if b.config.AMIName == "" { if b.config.AMIName == "" {
errs = packer.MultiErrorAppend( errs = packer.MultiErrorAppend(
errs, errors.New("ami_name must be specified")) errs, errors.New("ami_name must be specified"))
} else { } else if b.config.AMIName, err = b.config.tpl.Process(b.config.AMIName, nil); err != nil {
_, err = template.New("ami").Parse(b.config.AMIName) errs = packer.MultiErrorAppend(errs, err)
}
newTags := make(map[string]string)
for k, v := range b.config.Tags {
k, err = b.config.tpl.Process(k, nil)
if err != nil { if err != nil {
errs = packer.MultiErrorAppend( errs = packer.MultiErrorAppend(errs,
errs, fmt.Errorf("Failed parsing ami_name: %s", err)) fmt.Errorf("Error processing tag key %s: %s", k, err))
continue
} }
v, err = b.config.tpl.Process(v, nil)
if err != nil {
errs = packer.MultiErrorAppend(errs,
fmt.Errorf("Error processing tag value '%s': %s", v, err))
continue
} }
newTags[k] = v
}
b.config.Tags = newTags
if errs != nil && len(errs.Errors) > 0 { if errs != nil && len(errs.Errors) > 0 {
return errs return errs
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment