diff --git a/builder/vagrant/builder.go b/builder/vagrant/builder.go index ac156a38f..33fa878d4 100644 --- a/builder/vagrant/builder.go +++ b/builder/vagrant/builder.go @@ -125,9 +125,12 @@ type Config struct { AddInsecure bool `mapstructure:"add_insecure" required:"false"` // if true, Packer will not call vagrant package to // package your base box into its own standalone .box file. - SkipPackage bool `mapstructure:"skip_package" required:"false"` - OutputVagrantfile string `mapstructure:"output_vagrantfile"` - PackageInclude []string `mapstructure:"package_include"` + SkipPackage bool `mapstructure:"skip_package" required:"false"` + OutputVagrantfile string `mapstructure:"output_vagrantfile"` + // Equivalent to setting the + // [`--include`](https://www.vagrantup.com/docs/cli/package.html#include-x-y-z) option + // in `vagrant package`; defaults to unset + PackageInclude []string `mapstructure:"package_include"` ctx interpolate.Context } @@ -193,6 +196,19 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) { } } + if len(b.config.PackageInclude) > 0 { + include := []string{} + for i, inclFile := range b.config.PackageInclude { + b.config.PackageInclude, err = filepath.Abs(b.config.PackageInclude) + if err != nil { + packer.MultiErrorAppend(errs, + fmt.Errorf("unable to determine absolute path for file to be included: %s", inclFile)) + } + include = append(include, inclFile) + } + b.config.PackageInclude = include + } + if b.config.TeardownMethod == "" { // If we're using a box that's already opened on the system, don't // automatically destroy it. If we open the box ourselves, then go ahead