diff --git a/builder/amazon/chroot/step_mount_device.go b/builder/amazon/chroot/step_mount_device.go index dee71b456..2dcb94945 100644 --- a/builder/amazon/chroot/step_mount_device.go +++ b/builder/amazon/chroot/step_mount_device.go @@ -8,8 +8,14 @@ import ( "log" "os" "os/exec" + "path/filepath" + "text/template" ) +type mountPathData struct { + Device string +} + // StepMountDevice mounts the attached device. // // Produces: @@ -23,7 +29,13 @@ func (s *StepMountDevice) Run(state map[string]interface{}) multistep.StepAction ui := state["ui"].(packer.Ui) device := state["device"].(string) - mountPath := config.MountPath + mountPathRaw := new(bytes.Buffer) + t := template.Must(template.New("mountPath").Parse(config.MountPath)) + t.Execute(mountPathRaw, &mountPathData{ + Device: filepath.Basename(device), + }) + + mountPath := mountPathRaw.String() log.Printf("Mount path: %s", mountPath) if err := os.MkdirAll(mountPath, 0755); err != nil { @@ -46,6 +58,9 @@ func (s *StepMountDevice) Run(state map[string]interface{}) multistep.StepAction return multistep.ActionHalt } + // Set the mount path so we remember to unmount it later + s.mountPath = mountPath + return multistep.ActionContinue }