From 2ac9f5a276a68fd318e604686aee6dd6990d67ad Mon Sep 17 00:00:00 2001 From: Vladislav Rassokhin Date: Sun, 2 Aug 2020 21:09:47 +0300 Subject: [PATCH] Fixup for #8883: interpolate in file provisioner * `UploadDir` should receive interpolated `Destination` * Render `Destination` only once --- provisioner/file/provisioner.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/provisioner/file/provisioner.go b/provisioner/file/provisioner.go index 82e69570d..a75502e76 100644 --- a/provisioner/file/provisioner.go +++ b/provisioner/file/provisioner.go @@ -109,15 +109,15 @@ func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.C } func (p *Provisioner) ProvisionDownload(ui packer.Ui, comm packer.Communicator) error { + dst, err := interpolate.Render(p.config.Destination, &p.config.ctx) + if err != nil { + return fmt.Errorf("Error interpolating destination: %s", err) + } for _, src := range p.config.Sources { src, err := interpolate.Render(src, &p.config.ctx) if err != nil { return fmt.Errorf("Error interpolating source: %s", err) } - dst, err := interpolate.Render(p.config.Destination, &p.config.ctx) - if err != nil { - return fmt.Errorf("Error interpolating destination: %s", err) - } ui.Say(fmt.Sprintf("Downloading %s => %s", src, dst)) // ensure destination dir exists. p.config.Destination may either be a file or a dir. @@ -158,17 +158,16 @@ func (p *Provisioner) ProvisionDownload(ui packer.Ui, comm packer.Communicator) } func (p *Provisioner) ProvisionUpload(ui packer.Ui, comm packer.Communicator) error { + dst, err := interpolate.Render(p.config.Destination, &p.config.ctx) + if err != nil { + return fmt.Errorf("Error interpolating destination: %s", err) + } for _, src := range p.config.Sources { src, err := interpolate.Render(src, &p.config.ctx) if err != nil { return fmt.Errorf("Error interpolating source: %s", err) } - dst, err := interpolate.Render(p.config.Destination, &p.config.ctx) - if err != nil { - return fmt.Errorf("Error interpolating destination: %s", err) - } - ui.Say(fmt.Sprintf("Uploading %s => %s", src, dst)) info, err := os.Stat(src) @@ -178,7 +177,7 @@ func (p *Provisioner) ProvisionUpload(ui packer.Ui, comm packer.Communicator) er // If we're uploading a directory, short circuit and do that if info.IsDir() { - return comm.UploadDir(p.config.Destination, src, nil) + return comm.UploadDir(dst, src, nil) } // We're uploading a file...