From 31b93a3026761e4d6f6a5db4f85704b1690ab50d Mon Sep 17 00:00:00 2001 From: Rickard von Essen Date: Fri, 2 Jun 2017 21:58:34 +0200 Subject: [PATCH] virtualbox: Don't add portforwarding if comm = none Closes: #4959 --- builder/virtualbox/common/step_export.go | 6 +++--- builder/virtualbox/common/step_forward_ssh.go | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/builder/virtualbox/common/step_export.go b/builder/virtualbox/common/step_export.go index 4e7a6411f..adc04e40f 100644 --- a/builder/virtualbox/common/step_export.go +++ b/builder/virtualbox/common/step_export.go @@ -41,10 +41,10 @@ func (s *StepExport) Run(state multistep.StateBag) multistep.StepAction { ui.Say("Preparing to export machine...") // Clear out the Packer-created forwarding rule - if !s.SkipNatMapping { + sshPort := state.Get("sshHostPort") + if !s.SkipNatMapping && sshPort != 0 { ui.Message(fmt.Sprintf( - "Deleting forwarded port mapping for the communicator (SSH, WinRM, etc) (host port %d)", - state.Get("sshHostPort"))) + "Deleting forwarded port mapping for the communicator (SSH, WinRM, etc) (host port %d)", sshPort)) command := []string{"modifyvm", vmName, "--natpf1", "delete", "packercomm"} if err := driver.VBoxManage(command...); err != nil { err := fmt.Errorf("Error deleting port forwarding rule: %s", err) diff --git a/builder/virtualbox/common/step_forward_ssh.go b/builder/virtualbox/common/step_forward_ssh.go index 002397395..391573ced 100644 --- a/builder/virtualbox/common/step_forward_ssh.go +++ b/builder/virtualbox/common/step_forward_ssh.go @@ -32,6 +32,12 @@ func (s *StepForwardSSH) Run(state multistep.StateBag) multistep.StepAction { ui := state.Get("ui").(packer.Ui) vmName := state.Get("vmName").(string) + if s.CommConfig.Type == "none" { + log.Printf("Not using a communicator, skipping setting up port forwarding...") + state.Put("sshHostPort", 0) + return multistep.ActionContinue + } + guestPort := s.CommConfig.Port() sshHostPort := guestPort if !s.SkipNatMapping {