Commit 716d68bf authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/amazon: more efficient use of templates

parent c5e52377
...@@ -61,7 +61,7 @@ func (b *Builder) Prepare(raws ...interface{}) error { ...@@ -61,7 +61,7 @@ func (b *Builder) Prepare(raws ...interface{}) error {
} }
if b.config.BundlePrefix == "" { if b.config.BundlePrefix == "" {
b.config.BundlePrefix = "image-{{.CreateTime}}" b.config.BundlePrefix = "image-{{timestamp}}"
} }
if b.config.BundleUploadCommand == "" { if b.config.BundleUploadCommand == "" {
...@@ -97,7 +97,6 @@ func (b *Builder) Prepare(raws ...interface{}) error { ...@@ -97,7 +97,6 @@ func (b *Builder) Prepare(raws ...interface{}) error {
errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare(b.config.tpl)...) errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare(b.config.tpl)...)
validates := map[string]*string{ validates := map[string]*string{
"bundle_prefix": &b.config.BundlePrefix,
"bundle_upload_command": &b.config.BundleUploadCommand, "bundle_upload_command": &b.config.BundleUploadCommand,
"bundle_vol_command": &b.config.BundleVolCommand, "bundle_vol_command": &b.config.BundleVolCommand,
} }
...@@ -113,6 +112,7 @@ func (b *Builder) Prepare(raws ...interface{}) error { ...@@ -113,6 +112,7 @@ func (b *Builder) Prepare(raws ...interface{}) error {
"account_id": &b.config.AccountId, "account_id": &b.config.AccountId,
"ami_name": &b.config.AMIName, "ami_name": &b.config.AMIName,
"bundle_destination": &b.config.BundleDestination, "bundle_destination": &b.config.BundleDestination,
"bundle_prefix": &b.config.BundlePrefix,
"s3_bucket": &b.config.S3Bucket, "s3_bucket": &b.config.S3Bucket,
"x509_cert_path": &b.config.X509CertPath, "x509_cert_path": &b.config.X509CertPath,
"x509_key_path": &b.config.X509KeyPath, "x509_key_path": &b.config.X509KeyPath,
......
...@@ -115,7 +115,7 @@ func TestBuilderPrepare_BundlePrefix(t *testing.T) { ...@@ -115,7 +115,7 @@ func TestBuilderPrepare_BundlePrefix(t *testing.T) {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
if b.config.BundlePrefix != "image-{{.CreateTime}}" { if b.config.BundlePrefix == "" {
t.Fatalf("bad: %s", b.config.BundlePrefix) t.Fatalf("bad: %s", b.config.BundlePrefix)
} }
} }
......
...@@ -5,8 +5,6 @@ import ( ...@@ -5,8 +5,6 @@ import (
"github.com/mitchellh/goamz/ec2" "github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"strconv"
"time"
) )
type bundleCmdData struct { type bundleCmdData struct {
...@@ -19,10 +17,6 @@ type bundleCmdData struct { ...@@ -19,10 +17,6 @@ type bundleCmdData struct {
PrivatePath string PrivatePath string
} }
type bundlePrefixData struct {
CreateTime string
}
type StepBundleVolume struct{} type StepBundleVolume struct{}
func (s *StepBundleVolume) Run(state map[string]interface{}) multistep.StepAction { func (s *StepBundleVolume) Run(state map[string]interface{}) multistep.StepAction {
...@@ -54,16 +48,6 @@ func (s *StepBundleVolume) Run(state map[string]interface{}) multistep.StepActio ...@@ -54,16 +48,6 @@ func (s *StepBundleVolume) Run(state map[string]interface{}) multistep.StepActio
// Bundle the volume // Bundle the volume
var err error var err error
config.BundlePrefix, err = config.tpl.Process(config.BundlePrefix, bundlePrefixData{
CreateTime: strconv.FormatInt(time.Now().UTC().Unix(), 10),
})
if err != nil {
err := fmt.Errorf("Error processing bundle prefix: %s", err)
state["error"] = err
ui.Error(err.Error())
return multistep.ActionHalt
}
config.BundleVolCommand, err = config.tpl.Process(config.BundleVolCommand, bundleCmdData{ config.BundleVolCommand, err = config.tpl.Process(config.BundleVolCommand, bundleCmdData{
AccountId: config.AccountId, AccountId: config.AccountId,
Architecture: instance.Architecture, Architecture: instance.Architecture,
......
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