From bf67c6c36e14a91da2ab8ece368a144026afc225 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 8 Aug 2013 16:31:34 -0700 Subject: [PATCH] provisioner/file: use the template processing stuff --- provisioner/file/provisioner.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/provisioner/file/provisioner.go b/provisioner/file/provisioner.go index abdda9e42..ea958dba0 100644 --- a/provisioner/file/provisioner.go +++ b/provisioner/file/provisioner.go @@ -14,6 +14,8 @@ type config struct { // The remote path where the local file will be uploaded to. Destination string + + tpl *common.Template } type Provisioner struct { @@ -26,9 +28,28 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { return err } + p.config.tpl, err = common.NewTemplate() + if err != nil { + return err + } + // Accumulate any errors errs := common.CheckUnusedConfig(md) + templates := map[string]*string{ + "source": &p.config.Source, + "destination": &p.config.Destination, + } + + for n, ptr := range templates { + var err error + *ptr, err = p.config.tpl.Process(*ptr, nil) + if err != nil { + errs = packer.MultiErrorAppend( + errs, fmt.Errorf("Error processing %s: %s", n, err)) + } + } + if _, err := os.Stat(p.config.Source); err != nil { errs = packer.MultiErrorAppend(errs, fmt.Errorf("Bad source '%s': %s", p.config.Source, err))