diff --git a/builder/amazon/instance/builder.go b/builder/amazon/instance/builder.go index d9b367b2f..503af210a 100644 --- a/builder/amazon/instance/builder.go +++ b/builder/amazon/instance/builder.go @@ -53,7 +53,7 @@ func (b *Builder) Prepare(raws ...interface{}) error { } if b.config.BundlePrefix == "" { - b.config.BundlePrefix = "image" + b.config.BundlePrefix = "image-{{.CreateTime}}" } if b.config.BundleUploadCommand == "" { diff --git a/builder/amazon/instance/builder_test.go b/builder/amazon/instance/builder_test.go index 6febf7b8b..2e6b3639a 100644 --- a/builder/amazon/instance/builder_test.go +++ b/builder/amazon/instance/builder_test.go @@ -86,7 +86,7 @@ func TestBuilderPrepare_BundlePrefix(t *testing.T) { t.Fatalf("err: %s", err) } - if b.config.BundlePrefix != "image" { + if b.config.BundlePrefix != "image-{{.CreateTime}}" { t.Fatalf("bad: %s", b.config.BundlePrefix) } } diff --git a/builder/amazon/instance/step_bundle_volume.go b/builder/amazon/instance/step_bundle_volume.go index 139268a95..23fb7a415 100644 --- a/builder/amazon/instance/step_bundle_volume.go +++ b/builder/amazon/instance/step_bundle_volume.go @@ -6,7 +6,9 @@ import ( "github.com/mitchellh/goamz/ec2" "github.com/mitchellh/multistep" "github.com/mitchellh/packer/packer" + "strconv" "text/template" + "time" ) type bundleCmdData struct { @@ -19,6 +21,10 @@ type bundleCmdData struct { PrivatePath string } +type bundlePrefixData struct { + CreateTime string +} + type StepBundleVolume struct{} func (s *StepBundleVolume) Run(state map[string]interface{}) multistep.StepAction { @@ -49,6 +55,13 @@ func (s *StepBundleVolume) Run(state map[string]interface{}) multistep.StepActio } // Bundle the volume + var bundlePrefix bytes.Buffer + prefixTData := bundlePrefixData{ + CreateTime: strconv.FormatInt(time.Now().UTC().Unix(), 10), + } + t := template.Must(template.New("bundlePrefix").Parse(config.BundlePrefix)) + t.Execute(&bundlePrefix, prefixTData) + var bundleCmd bytes.Buffer tData := bundleCmdData{ AccountId: config.AccountId, @@ -56,10 +69,10 @@ func (s *StepBundleVolume) Run(state map[string]interface{}) multistep.StepActio CertPath: x509RemoteCertPath, Destination: config.BundleDestination, KeyPath: x509RemoteKeyPath, - Prefix: config.BundlePrefix, + Prefix: bundlePrefix.String(), PrivatePath: config.X509UploadPath, } - t := template.Must(template.New("bundleCmd").Parse(config.BundleVolCommand)) + t = template.Must(template.New("bundleCmd").Parse(config.BundleVolCommand)) t.Execute(&bundleCmd, tData) ui.Say("Bundling the volume...") @@ -79,6 +92,10 @@ func (s *StepBundleVolume) Run(state map[string]interface{}) multistep.StepActio return multistep.ActionHalt } + // Store the manifest path + state["manifest_path"] = fmt.Sprintf( + "%s/%s.manifest.xml", config.BundleDestination, bundlePrefix.String()) + return multistep.ActionContinue } diff --git a/builder/amazon/instance/step_upload_bundle.go b/builder/amazon/instance/step_upload_bundle.go index 87cfb7e6e..827daf8b0 100644 --- a/builder/amazon/instance/step_upload_bundle.go +++ b/builder/amazon/instance/step_upload_bundle.go @@ -21,6 +21,7 @@ type StepUploadBundle struct{} func (s *StepUploadBundle) Run(state map[string]interface{}) multistep.StepAction { comm := state["communicator"].(packer.Communicator) config := state["config"].(*Config) + manifestPath := state["manifest_path"].(string) ui := state["ui"].(packer.Ui) var uploadCmd bytes.Buffer @@ -28,9 +29,8 @@ func (s *StepUploadBundle) Run(state map[string]interface{}) multistep.StepActio AccessKey: config.AccessKey, BucketName: config.S3Bucket, BundleDirectory: config.BundleDestination, - ManifestPath: fmt.Sprintf( - "%s/%s.manifest.xml", config.BundleDestination, config.BundlePrefix), - SecretKey: config.SecretKey, + ManifestPath: manifestPath, + SecretKey: config.SecretKey, } t := template.Must(template.New("uploadCmd").Parse(config.BundleUploadCommand)) t.Execute(&uploadCmd, tData)