diff --git a/builder/vagrant/builder.go b/builder/vagrant/builder.go index 338f16de8..66ef1843e 100644 --- a/builder/vagrant/builder.go +++ b/builder/vagrant/builder.go @@ -199,6 +199,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack &StepCreateVagrantfile{ Template: b.config.Template, SyncedFolder: b.config.SyncedFolder, + SourceBox: b.config.SourceBox, BoxName: b.config.BoxName, OutputDir: b.config.OutputDir, GlobalID: b.config.GlobalID, diff --git a/builder/vagrant/step_create_vagrantfile.go b/builder/vagrant/step_create_vagrantfile.go index 1d1c890dd..5101c6335 100644 --- a/builder/vagrant/step_create_vagrantfile.go +++ b/builder/vagrant/step_create_vagrantfile.go @@ -17,11 +17,18 @@ type StepCreateVagrantfile struct { OutputDir string SyncedFolder string GlobalID string + SourceBox string BoxName string } var DEFAULT_TEMPLATE = `Vagrant.configure("2") do |config| - config.vm.box = "{{.BoxName}}" + config.vm.define "source", autostart: false do |source| + source.vm.box = "{{.SourceBox}}" + end + config.vm.define "output" do |output| + output.vm.box = "{{.BoxName}}" + output.vm.box_url = "file://package.box" + end {{ if ne .SyncedFolder "" -}} config.vm.synced_folder "{{.SyncedFolder}}", "/vagrant" {{- else -}} @@ -31,6 +38,7 @@ end` type VagrantfileOptions struct { SyncedFolder string + SourceBox string BoxName string } @@ -57,6 +65,7 @@ func (s *StepCreateVagrantfile) createVagrantfile() (string, error) { opts := &VagrantfileOptions{ SyncedFolder: s.SyncedFolder, BoxName: s.BoxName, + SourceBox: s.SourceBox, } err = tpl.Execute(templateFile, opts) diff --git a/builder/vagrant/step_create_vagrantfile_test.go b/builder/vagrant/step_create_vagrantfile_test.go index 50a294499..93ef81702 100644 --- a/builder/vagrant/step_create_vagrantfile_test.go +++ b/builder/vagrant/step_create_vagrantfile_test.go @@ -20,6 +20,7 @@ func TestStepCreateVagrantfile_Impl(t *testing.T) { func TestCreateFile(t *testing.T) { testy := StepCreateVagrantfile{ OutputDir: "./", + SourceBox: "apples", BoxName: "bananas", } templatePath, err := testy.createVagrantfile() @@ -30,7 +31,13 @@ func TestCreateFile(t *testing.T) { contents, err := ioutil.ReadFile(templatePath) actual := string(contents) expected := `Vagrant.configure("2") do |config| - config.vm.box = "bananas" + config.vm.define "source", autostart: false do |source| + source.vm.box = "apples" + end + config.vm.define "output" do |output| + output.vm.box = "bananas" + output.vm.box_url = "file://package.box" + end config.vm.synced_folder ".", "/vagrant", disabled: true end` if ok := strings.Compare(actual, expected); ok != 0 { @@ -51,7 +58,13 @@ func TestCreateFile_customSync(t *testing.T) { contents, err := ioutil.ReadFile(templatePath) actual := string(contents) expected := `Vagrant.configure("2") do |config| - config.vm.box = "" + config.vm.define "source", autostart: false do |source| + source.vm.box = "" + end + config.vm.define "output" do |output| + output.vm.box = "" + output.vm.box_url = "file://package.box" + end config.vm.synced_folder "myfolder/foldertimes", "/vagrant" end` if ok := strings.Compare(actual, expected); ok != 0 { diff --git a/builder/vagrant/step_up.go b/builder/vagrant/step_up.go index 23284f852..9caa711b0 100644 --- a/builder/vagrant/step_up.go +++ b/builder/vagrant/step_up.go @@ -20,7 +20,8 @@ func (s *StepUp) Run(ctx context.Context, state multistep.StateBag) multistep.St ui.Say("Calling Vagrant Up...") - var args []string + // start only the source box + args := []string{"source"} if s.GlobalID != "" { args = append(args, s.GlobalID) }