diff --git a/builder/vagrant/builder.go b/builder/vagrant/builder.go index 263fb6b76..c5110ede6 100644 --- a/builder/vagrant/builder.go +++ b/builder/vagrant/builder.go @@ -138,9 +138,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 } @@ -192,7 +195,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) { } if strings.HasSuffix(b.config.SourceBox, ".box") { if _, err := os.Stat(b.config.SourceBox); err != nil { - packer.MultiErrorAppend(errs, + errs = packer.MultiErrorAppend(errs, fmt.Errorf("Source box '%s' needs to exist at time of config validation! %v", b.config.SourceBox, err)) } } @@ -201,11 +204,22 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) { if b.config.OutputVagrantfile != "" { b.config.OutputVagrantfile, err = filepath.Abs(b.config.OutputVagrantfile) if err != nil { - packer.MultiErrorAppend(errs, + errs = packer.MultiErrorAppend(errs, fmt.Errorf("unable to determine absolute path for output vagrantfile: %s", err)) } } + if len(b.config.PackageInclude) > 0 { + for i, rawFile := range b.config.PackageInclude { + inclFile, err := filepath.Abs(rawFile) + if err != nil { + errs = packer.MultiErrorAppend(errs, + fmt.Errorf("unable to determine absolute path for file to be included: %s", rawFile)) + } + b.config.PackageInclude[i] = inclFile + } + } + 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 diff --git a/website/pages/partials/builder/vagrant/Config-not-required.mdx b/website/pages/partials/builder/vagrant/Config-not-required.mdx index 783b45943..c310345fd 100644 --- a/website/pages/partials/builder/vagrant/Config-not-required.mdx +++ b/website/pages/partials/builder/vagrant/Config-not-required.mdx @@ -83,4 +83,7 @@ package your base box into its own standalone .box file. - `output_vagrantfile` (string) - Output Vagrantfile -- `package_include` ([]string) - Package Include \ No newline at end of file +- `package_include` ([]string) - Equivalent to setting the + [`--include`](https://www.vagrantup.com/docs/cli/package.html#include-x-y-z) option + in `vagrant package`; defaults to unset + \ No newline at end of file