Rename communicator config variables and remove deprecated code (#8584)

This commit is contained in:
Sylvia Moss 2020-01-09 08:37:30 -08:00 committed by GitHub
parent baa203bb53
commit d6a351b173
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
33 changed files with 624 additions and 210 deletions

View File

@ -1,8 +1,6 @@
package common
import (
"time"
"github.com/hashicorp/packer/helper/communicator"
"github.com/hashicorp/packer/template/interpolate"
)
@ -10,18 +8,9 @@ import (
// SSHConfig contains the configuration for SSH communicator.
type SSHConfig struct {
Comm communicator.Config `mapstructure:",squash"`
// These are deprecated, but we keep them around for BC
// TODO(@mitchellh): remove
SSHWaitTimeout time.Duration `mapstructure:"ssh_wait_timeout"`
}
// Prepare sets the default values for SSH communicator properties.
func (c *SSHConfig) Prepare(ctx *interpolate.Context) []error {
// TODO: backwards compatibility, write fixer instead
if c.SSHWaitTimeout != 0 {
c.Comm.SSHTimeout = c.SSHWaitTimeout
}
return c.Comm.Prepare(ctx)
}

View File

@ -82,7 +82,6 @@ type FlatConfig struct {
WinRMUseSSL *bool `mapstructure:"winrm_use_ssl" cty:"winrm_use_ssl"`
WinRMInsecure *bool `mapstructure:"winrm_insecure" cty:"winrm_insecure"`
WinRMUseNTLM *bool `mapstructure:"winrm_use_ntlm" cty:"winrm_use_ntlm"`
SSHWaitTimeout *string `mapstructure:"ssh_wait_timeout" cty:"ssh_wait_timeout"`
ParallelsToolsFlavor *string `mapstructure:"parallels_tools_flavor" required:"true" cty:"parallels_tools_flavor"`
ParallelsToolsGuestPath *string `mapstructure:"parallels_tools_guest_path" required:"false" cty:"parallels_tools_guest_path"`
ParallelsToolsMode *string `mapstructure:"parallels_tools_mode" required:"false" cty:"parallels_tools_mode"`
@ -180,7 +179,6 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec {
"winrm_use_ssl": &hcldec.AttrSpec{Name: "winrm_use_ssl", Type: cty.Bool, Required: false},
"winrm_insecure": &hcldec.AttrSpec{Name: "winrm_insecure", Type: cty.Bool, Required: false},
"winrm_use_ntlm": &hcldec.AttrSpec{Name: "winrm_use_ntlm", Type: cty.Bool, Required: false},
"ssh_wait_timeout": &hcldec.AttrSpec{Name: "ssh_wait_timeout", Type: cty.String, Required: false},
"parallels_tools_flavor": &hcldec.AttrSpec{Name: "parallels_tools_flavor", Type: cty.String, Required: false},
"parallels_tools_guest_path": &hcldec.AttrSpec{Name: "parallels_tools_guest_path", Type: cty.String, Required: false},
"parallels_tools_mode": &hcldec.AttrSpec{Name: "parallels_tools_mode", Type: cty.String, Required: false},

View File

@ -63,7 +63,6 @@ type FlatConfig struct {
WinRMUseSSL *bool `mapstructure:"winrm_use_ssl" cty:"winrm_use_ssl"`
WinRMInsecure *bool `mapstructure:"winrm_insecure" cty:"winrm_insecure"`
WinRMUseNTLM *bool `mapstructure:"winrm_use_ntlm" cty:"winrm_use_ntlm"`
SSHWaitTimeout *string `mapstructure:"ssh_wait_timeout" cty:"ssh_wait_timeout"`
ShutdownCommand *string `mapstructure:"shutdown_command" required:"false" cty:"shutdown_command"`
ShutdownTimeout *string `mapstructure:"shutdown_timeout" required:"false" cty:"shutdown_timeout"`
BootGroupInterval *string `mapstructure:"boot_keygroup_interval" cty:"boot_keygroup_interval"`
@ -144,7 +143,6 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec {
"winrm_use_ssl": &hcldec.AttrSpec{Name: "winrm_use_ssl", Type: cty.Bool, Required: false},
"winrm_insecure": &hcldec.AttrSpec{Name: "winrm_insecure", Type: cty.Bool, Required: false},
"winrm_use_ntlm": &hcldec.AttrSpec{Name: "winrm_use_ntlm", Type: cty.Bool, Required: false},
"ssh_wait_timeout": &hcldec.AttrSpec{Name: "ssh_wait_timeout", Type: cty.String, Required: false},
"shutdown_command": &hcldec.AttrSpec{Name: "shutdown_command", Type: cty.String, Required: false},
"shutdown_timeout": &hcldec.AttrSpec{Name: "shutdown_timeout", Type: cty.String, Required: false},
"boot_keygroup_interval": &hcldec.AttrSpec{Name: "boot_keygroup_interval", Type: cty.String, Required: false},

View File

@ -14,7 +14,6 @@ import (
"regexp"
"runtime"
"strings"
"time"
"github.com/hashicorp/hcl/v2/hcldec"
"github.com/hashicorp/packer/common"
@ -327,9 +326,6 @@ type Config struct {
// "BUILDNAME" is the name of the build. Currently, no file extension will be
// used unless it is specified in this option.
VMName string `mapstructure:"vm_name" required:"false"`
// These are deprecated, but we keep them around for BC
// TODO(@mitchellh): remove
SSHWaitTimeout time.Duration `mapstructure:"ssh_wait_timeout" required:"false"`
// TODO(mitchellh): deprecate
RunOnce bool `mapstructure:"run_once"`
@ -472,11 +468,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
b.config.DiskInterface = "virtio"
}
// TODO: backwards compatibility, write fixer instead
if b.config.SSHWaitTimeout != 0 {
b.config.Comm.SSHTimeout = b.config.SSHWaitTimeout
}
if b.config.ISOSkipCache {
b.config.ISOChecksumType = "none"
}

View File

@ -108,7 +108,6 @@ type FlatConfig struct {
VNCPortMin *int `mapstructure:"vnc_port_min" required:"false" cty:"vnc_port_min"`
VNCPortMax *int `mapstructure:"vnc_port_max" cty:"vnc_port_max"`
VMName *string `mapstructure:"vm_name" required:"false" cty:"vm_name"`
SSHWaitTimeout *string `mapstructure:"ssh_wait_timeout" required:"false" cty:"ssh_wait_timeout"`
RunOnce *bool `mapstructure:"run_once" cty:"run_once"`
}
@ -223,7 +222,6 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec {
"vnc_port_min": &hcldec.AttrSpec{Name: "vnc_port_min", Type: cty.Number, Required: false},
"vnc_port_max": &hcldec.AttrSpec{Name: "vnc_port_max", Type: cty.Number, Required: false},
"vm_name": &hcldec.AttrSpec{Name: "vm_name", Type: cty.String, Required: false},
"ssh_wait_timeout": &hcldec.AttrSpec{Name: "ssh_wait_timeout", Type: cty.String, Required: false},
"run_once": &hcldec.AttrSpec{Name: "run_once", Type: cty.Bool, Required: false},
}
return s

View File

@ -531,7 +531,7 @@ func TestBuilderPrepare_SSHWaitTimeout(t *testing.T) {
config := testConfig()
// Test a default boot_wait
delete(config, "ssh_wait_timeout")
delete(config, "ssh_timeout")
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
@ -541,7 +541,7 @@ func TestBuilderPrepare_SSHWaitTimeout(t *testing.T) {
}
// Test with a bad value
config["ssh_wait_timeout"] = "this is not good"
config["ssh_timeout"] = "this is not good"
b = Builder{}
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
@ -552,7 +552,7 @@ func TestBuilderPrepare_SSHWaitTimeout(t *testing.T) {
}
// Test with a good one
config["ssh_wait_timeout"] = "5s"
config["ssh_timeout"] = "5s"
b = Builder{}
_, warns, err = b.Prepare(config)
if len(warns) > 0 {

View File

@ -10,7 +10,7 @@ func CommHost(host string) func(multistep.StateBag) (string, error) {
}
}
func SSHPort(state multistep.StateBag) (int, error) {
sshHostPort := state.Get("sshHostPort").(int)
return sshHostPort, nil
func CommPort(state multistep.StateBag) (int, error) {
commHostPort := state.Get("commHostPort").(int)
return commHostPort, nil
}

View File

@ -0,0 +1,71 @@
//go:generate struct-markdown
package common
import (
"errors"
"github.com/hashicorp/packer/helper/communicator"
"github.com/hashicorp/packer/template/interpolate"
)
type CommConfig struct {
Comm communicator.Config `mapstructure:",squash"`
// The minimum port to use for the Communicator port on the host machine which is forwarded
// to the SSH or WinRM port on the guest machine. By default this is 2222.
HostPortMin int `mapstructure:"host_port_min" required:"false"`
// The maximum port to use for the Communicator port on the host machine which is forwarded
// to the SSH or WinRM port on the guest machine. Because Packer often runs in parallel,
// Packer will choose a randomly available port in this range to use as the
// host port. By default this is 4444.
HostPortMax int `mapstructure:"host_port_max" required:"false"`
// Defaults to false. When enabled, Packer
// does not setup forwarded port mapping for communicator (SSH or WinRM) requests and uses ssh_port or winrm_port
// on the host to communicate to the virtual machine.
SkipNatMapping bool `mapstructure:"skip_nat_mapping" required:"false"`
// These are deprecated, but we keep them around for backwards compatibility
// TODO: remove later
SSHHostPortMin int `mapstructure:"ssh_host_port_min" required:"false"`
// TODO: remove later
SSHHostPortMax int `mapstructure:"ssh_host_port_max"`
// TODO: remove later
SSHSkipNatMapping bool `mapstructure:"ssh_skip_nat_mapping" required:"false"`
}
func (c *CommConfig) Prepare(ctx *interpolate.Context) []error {
// Backwards compatibility
if c.SSHHostPortMin != 0 {
c.HostPortMin = c.SSHHostPortMin
}
// Backwards compatibility
if c.SSHHostPortMax != 0 {
c.HostPortMax = c.SSHHostPortMax
}
// Backwards compatibility
if c.SSHSkipNatMapping {
c.SkipNatMapping = c.SSHSkipNatMapping
}
if c.Comm.SSHHost == "" {
c.Comm.SSHHost = "127.0.0.1"
}
if c.HostPortMin == 0 {
c.HostPortMin = 2222
}
if c.HostPortMax == 0 {
c.HostPortMax = 4444
}
errs := c.Comm.Prepare(ctx)
if c.HostPortMin > c.HostPortMax {
errs = append(errs,
errors.New("host_port_min must be less than host_port_max"))
}
return errs
}

View File

@ -9,8 +9,8 @@ import (
"github.com/hashicorp/packer/template/interpolate"
)
func testSSHConfig() *SSHConfig {
return &SSHConfig{
func testCommConfig() *CommConfig {
return &CommConfig{
Comm: communicator.Config{
SSH: communicator.SSH{
SSHUsername: "foo",
@ -19,61 +19,61 @@ func testSSHConfig() *SSHConfig {
}
}
func TestSSHConfigPrepare(t *testing.T) {
c := testSSHConfig()
func TestCommConfigPrepare(t *testing.T) {
c := testCommConfig()
errs := c.Prepare(interpolate.NewContext())
if len(errs) > 0 {
t.Fatalf("err: %#v", errs)
}
if c.SSHHostPortMin != 2222 {
t.Errorf("bad min ssh host port: %d", c.SSHHostPortMin)
if c.HostPortMin != 2222 {
t.Errorf("bad min communicator host port: %d", c.HostPortMin)
}
if c.SSHHostPortMax != 4444 {
t.Errorf("bad max ssh host port: %d", c.SSHHostPortMax)
if c.HostPortMax != 4444 {
t.Errorf("bad max communicator host port: %d", c.HostPortMax)
}
if c.Comm.SSHPort != 22 {
t.Errorf("bad ssh port: %d", c.Comm.SSHPort)
t.Errorf("bad communicator port: %d", c.Comm.SSHPort)
}
}
func TestSSHConfigPrepare_SSHHostPort(t *testing.T) {
var c *SSHConfig
func TestCommConfigPrepare_SSHHostPort(t *testing.T) {
var c *CommConfig
var errs []error
// Bad
c = testSSHConfig()
c.SSHHostPortMin = 1000
c.SSHHostPortMax = 500
c = testCommConfig()
c.HostPortMin = 1000
c.HostPortMax = 500
errs = c.Prepare(interpolate.NewContext())
if len(errs) == 0 {
t.Fatalf("bad: %#v", errs)
}
// Good
c = testSSHConfig()
c.SSHHostPortMin = 50
c.SSHHostPortMax = 500
c = testCommConfig()
c.HostPortMin = 50
c.HostPortMax = 500
errs = c.Prepare(interpolate.NewContext())
if len(errs) > 0 {
t.Fatalf("should not have error: %s", errs)
}
}
func TestSSHConfigPrepare_SSHPrivateKey(t *testing.T) {
var c *SSHConfig
func TestCommConfigPrepare_SSHPrivateKey(t *testing.T) {
var c *CommConfig
var errs []error
c = testSSHConfig()
c = testCommConfig()
c.Comm.SSHPrivateKeyFile = ""
errs = c.Prepare(interpolate.NewContext())
if len(errs) > 0 {
t.Fatalf("should not have error: %#v", errs)
}
c = testSSHConfig()
c = testCommConfig()
c.Comm.SSHPrivateKeyFile = "/i/dont/exist"
errs = c.Prepare(interpolate.NewContext())
if len(errs) == 0 {
@ -92,7 +92,7 @@ func TestSSHConfigPrepare_SSHPrivateKey(t *testing.T) {
t.Fatalf("err: %s", err)
}
c = testSSHConfig()
c = testCommConfig()
c.Comm.SSHPrivateKeyFile = tf.Name()
errs = c.Prepare(interpolate.NewContext())
if len(errs) == 0 {
@ -103,7 +103,7 @@ func TestSSHConfigPrepare_SSHPrivateKey(t *testing.T) {
tf.Seek(0, 0)
tf.Truncate(0)
tf.Write([]byte(testPem))
c = testSSHConfig()
c = testCommConfig()
c.Comm.SSHPrivateKeyFile = tf.Name()
errs = c.Prepare(interpolate.NewContext())
if len(errs) > 0 {
@ -111,6 +111,35 @@ func TestSSHConfigPrepare_SSHPrivateKey(t *testing.T) {
}
}
func TestCommConfigPrepare_BackwardsCompatibility(t *testing.T) {
var c *CommConfig
hostPortMin := 1234
hostPortMax := 4321
skipNatMapping := true
c = testCommConfig()
c.SSHHostPortMin = hostPortMin
c.SSHHostPortMax = hostPortMax
c.SSHSkipNatMapping = skipNatMapping
err := c.Prepare(interpolate.NewContext())
if err != nil {
t.Fatalf("err: %s", err)
}
if c.HostPortMin != hostPortMin {
t.Fatalf("HostPortMin should be %d for backwards compatibility, but it was %d", hostPortMin, c.HostPortMin)
}
if c.HostPortMax != hostPortMax {
t.Fatalf("HostPortMax should be %d for backwards compatibility, but it was %d", hostPortMax, c.HostPortMax)
}
if c.SkipNatMapping != skipNatMapping {
t.Fatalf("SkipNatMapping should be %t for backwards compatibility, but it was %t", skipNatMapping, c.SkipNatMapping)
}
}
const testPem = `
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEAxd4iamvrwRJvtNDGQSIbNvvIQN8imXTRWlRY62EvKov60vqu

View File

@ -1,57 +0,0 @@
//go:generate struct-markdown
package common
import (
"errors"
"time"
"github.com/hashicorp/packer/helper/communicator"
"github.com/hashicorp/packer/template/interpolate"
)
type SSHConfig struct {
Comm communicator.Config `mapstructure:",squash"`
// The minimum and
// maximum port to use for the SSH port on the host machine which is forwarded
// to the SSH port on the guest machine. Because Packer often runs in parallel,
// Packer will choose a randomly available port in this range to use as the
// host port. By default this is 2222 to 4444.
SSHHostPortMin int `mapstructure:"ssh_host_port_min" required:"false"`
SSHHostPortMax int `mapstructure:"ssh_host_port_max"`
// Defaults to false. When enabled, Packer
// does not setup forwarded port mapping for SSH requests and uses ssh_port
// on the host to communicate to the virtual machine.
SSHSkipNatMapping bool `mapstructure:"ssh_skip_nat_mapping" required:"false"`
// These are deprecated, but we keep them around for BC
// TODO(@mitchellh): remove
SSHWaitTimeout time.Duration `mapstructure:"ssh_wait_timeout"`
}
func (c *SSHConfig) Prepare(ctx *interpolate.Context) []error {
if c.Comm.SSHHost == "" {
c.Comm.SSHHost = "127.0.0.1"
}
if c.SSHHostPortMin == 0 {
c.SSHHostPortMin = 2222
}
if c.SSHHostPortMax == 0 {
c.SSHHostPortMax = 4444
}
// TODO: backwards compatibility, write fixer instead
if c.SSHWaitTimeout != 0 {
c.Comm.SSHTimeout = c.SSHWaitTimeout
}
errs := c.Comm.Prepare(ctx)
if c.SSHHostPortMin > c.SSHHostPortMax {
errs = append(errs,
errors.New("ssh_host_port_min must be less than ssh_host_port_max"))
}
return errs
}

View File

@ -47,10 +47,10 @@ func (s *StepExport) Run(ctx context.Context, state multistep.StateBag) multiste
ui.Say("Preparing to export machine...")
// Clear out the Packer-created forwarding rule
sshPort := state.Get("sshHostPort")
if !s.SkipNatMapping && sshPort != 0 {
commPort := state.Get("commHostPort")
if !s.SkipNatMapping && commPort != 0 {
ui.Message(fmt.Sprintf(
"Deleting forwarded port mapping for the communicator (SSH, WinRM, etc) (host port %d)", sshPort))
"Deleting forwarded port mapping for the communicator (SSH, WinRM, etc) (host port %d)", commPort))
command := []string{"modifyvm", vmName, "--natpf1", "delete", "packercomm"}
if err := driver.VBoxManage(command...); err != nil {
err := fmt.Errorf("Error deleting port forwarding rule: %s", err)

View File

@ -12,7 +12,7 @@ import (
"github.com/hashicorp/packer/packer"
)
// This step adds a NAT port forwarding definition so that SSH is available
// This step adds a NAT port forwarding definition so that SSH or WinRM is available
// on the guest machine.
//
// Uses:
@ -21,7 +21,7 @@ import (
// vmName string
//
// Produces:
type StepForwardSSH struct {
type StepPortForwarding struct {
CommConfig *communicator.Config
HostPortMin int
HostPortMax int
@ -30,19 +30,19 @@ type StepForwardSSH struct {
l *net.Listener
}
func (s *StepForwardSSH) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
func (s *StepPortForwarding) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
driver := state.Get("driver").(Driver)
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)
state.Put("commHostPort", 0)
return multistep.ActionContinue
}
guestPort := s.CommConfig.Port()
sshHostPort := guestPort
commHostPort := guestPort
if !s.SkipNatMapping {
log.Printf("Looking for available communicator (SSH, WinRM, etc) port between %d and %d",
s.HostPortMin, s.HostPortMax)
@ -61,7 +61,7 @@ func (s *StepForwardSSH) Run(ctx context.Context, state multistep.StateBag) mult
return multistep.ActionHalt
}
s.l.Listener.Close() // free port, but don't unlock lock file
sshHostPort = s.l.Port
commHostPort = s.l.Port
// Make sure to configure the network interface to NAT
command := []string{
@ -77,11 +77,11 @@ func (s *StepForwardSSH) Run(ctx context.Context, state multistep.StateBag) mult
}
// Create a forwarded port mapping to the VM
ui.Say(fmt.Sprintf("Creating forwarded port mapping for communicator (SSH, WinRM, etc) (host port %d)", sshHostPort))
ui.Say(fmt.Sprintf("Creating forwarded port mapping for communicator (SSH, WinRM, etc) (host port %d)", commHostPort))
command = []string{
"modifyvm", vmName,
"--natpf1",
fmt.Sprintf("packercomm,tcp,127.0.0.1,%d,,%d", sshHostPort, guestPort),
fmt.Sprintf("packercomm,tcp,127.0.0.1,%d,,%d", commHostPort, guestPort),
}
retried := false
retry:
@ -110,12 +110,12 @@ func (s *StepForwardSSH) Run(ctx context.Context, state multistep.StateBag) mult
}
// Save the port we're using so that future steps can use it
state.Put("sshHostPort", sshHostPort)
state.Put("commHostPort", commHostPort)
return multistep.ActionContinue
}
func (s *StepForwardSSH) Cleanup(state multistep.StateBag) {
func (s *StepPortForwarding) Cleanup(state multistep.StateBag) {
if s.l != nil {
err := s.l.Close()
if err != nil {

View File

@ -37,7 +37,7 @@ type Config struct {
vboxcommon.OutputConfig `mapstructure:",squash"`
vboxcommon.RunConfig `mapstructure:",squash"`
vboxcommon.ShutdownConfig `mapstructure:",squash"`
vboxcommon.SSHConfig `mapstructure:",squash"`
vboxcommon.CommConfig `mapstructure:",squash"`
vboxcommon.HWConfig `mapstructure:",squash"`
vboxcommon.VBoxManageConfig `mapstructure:",squash"`
vboxcommon.VBoxVersionConfig `mapstructure:",squash"`
@ -167,7 +167,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
errs = packer.MultiErrorAppend(errs, b.config.HTTPConfig.Prepare(&b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare(&b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.ShutdownConfig.Prepare(&b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.SSHConfig.Prepare(&b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.CommConfig.Prepare(&b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.HWConfig.Prepare(&b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.VBoxBundleConfig.Prepare(&b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.VBoxManageConfig.Prepare(&b.config.ctx)...)
@ -332,11 +332,11 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
VRDPPortMax: b.config.VRDPPortMax,
},
new(vboxcommon.StepAttachFloppy),
&vboxcommon.StepForwardSSH{
CommConfig: &b.config.SSHConfig.Comm,
HostPortMin: b.config.SSHHostPortMin,
HostPortMax: b.config.SSHHostPortMax,
SkipNatMapping: b.config.SSHSkipNatMapping,
&vboxcommon.StepPortForwarding{
CommConfig: &b.config.CommConfig.Comm,
HostPortMin: b.config.HostPortMin,
HostPortMax: b.config.HostPortMax,
SkipNatMapping: b.config.SkipNatMapping,
},
&vboxcommon.StepVBoxManage{
Commands: b.config.VBoxManage,
@ -354,11 +354,11 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
Comm: &b.config.Comm,
},
&communicator.StepConnect{
Config: &b.config.SSHConfig.Comm,
Host: vboxcommon.CommHost(b.config.SSHConfig.Comm.SSHHost),
SSHConfig: b.config.SSHConfig.Comm.SSHConfigFunc(),
SSHPort: vboxcommon.SSHPort,
WinRMPort: vboxcommon.SSHPort,
Config: &b.config.CommConfig.Comm,
Host: vboxcommon.CommHost(b.config.CommConfig.Comm.SSHHost),
SSHConfig: b.config.CommConfig.Comm.SSHConfigFunc(),
SSHPort: vboxcommon.CommPort,
WinRMPort: vboxcommon.CommPort,
},
&vboxcommon.StepUploadVersion{
Path: *b.config.VBoxVersionFile,
@ -370,7 +370,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
},
new(common.StepProvision),
&common.StepCleanupTempKeys{
Comm: &b.config.SSHConfig.Comm,
Comm: &b.config.CommConfig.Comm,
},
&vboxcommon.StepShutdown{
Command: b.config.ShutdownCommand,
@ -392,7 +392,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
OutputDir: b.config.OutputDir,
ExportOpts: b.config.ExportConfig.ExportOpts,
Bundling: b.config.VBoxBundleConfig,
SkipNatMapping: b.config.SSHSkipNatMapping,
SkipNatMapping: b.config.SkipNatMapping,
SkipExport: b.config.SkipExport,
},
}

View File

@ -84,10 +84,12 @@ type FlatConfig struct {
WinRMUseSSL *bool `mapstructure:"winrm_use_ssl" cty:"winrm_use_ssl"`
WinRMInsecure *bool `mapstructure:"winrm_insecure" cty:"winrm_insecure"`
WinRMUseNTLM *bool `mapstructure:"winrm_use_ntlm" cty:"winrm_use_ntlm"`
HostPortMin *int `mapstructure:"host_port_min" required:"false" cty:"host_port_min"`
HostPortMax *int `mapstructure:"host_port_max" required:"false" cty:"host_port_max"`
SkipNatMapping *bool `mapstructure:"skip_nat_mapping" required:"false" cty:"skip_nat_mapping"`
SSHHostPortMin *int `mapstructure:"ssh_host_port_min" required:"false" cty:"ssh_host_port_min"`
SSHHostPortMax *int `mapstructure:"ssh_host_port_max" cty:"ssh_host_port_max"`
SSHSkipNatMapping *bool `mapstructure:"ssh_skip_nat_mapping" required:"false" cty:"ssh_skip_nat_mapping"`
SSHWaitTimeout *string `mapstructure:"ssh_wait_timeout" cty:"ssh_wait_timeout"`
CpuCount *int `mapstructure:"cpus" required:"false" cty:"cpus"`
MemorySize *int `mapstructure:"memory" required:"false" cty:"memory"`
Sound *string `mapstructure:"sound" required:"false" cty:"sound"`
@ -201,10 +203,12 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec {
"winrm_use_ssl": &hcldec.AttrSpec{Name: "winrm_use_ssl", Type: cty.Bool, Required: false},
"winrm_insecure": &hcldec.AttrSpec{Name: "winrm_insecure", Type: cty.Bool, Required: false},
"winrm_use_ntlm": &hcldec.AttrSpec{Name: "winrm_use_ntlm", Type: cty.Bool, Required: false},
"host_port_min": &hcldec.AttrSpec{Name: "host_port_min", Type: cty.Number, Required: false},
"host_port_max": &hcldec.AttrSpec{Name: "host_port_max", Type: cty.Number, Required: false},
"skip_nat_mapping": &hcldec.AttrSpec{Name: "skip_nat_mapping", Type: cty.Bool, Required: false},
"ssh_host_port_min": &hcldec.AttrSpec{Name: "ssh_host_port_min", Type: cty.Number, Required: false},
"ssh_host_port_max": &hcldec.AttrSpec{Name: "ssh_host_port_max", Type: cty.Number, Required: false},
"ssh_skip_nat_mapping": &hcldec.AttrSpec{Name: "ssh_skip_nat_mapping", Type: cty.Bool, Required: false},
"ssh_wait_timeout": &hcldec.AttrSpec{Name: "ssh_wait_timeout", Type: cty.String, Required: false},
"cpus": &hcldec.AttrSpec{Name: "cpus", Type: cty.Number, Required: false},
"memory": &hcldec.AttrSpec{Name: "memory", Type: cty.Number, Required: false},
"sound": &hcldec.AttrSpec{Name: "sound", Type: cty.String, Required: false},

View File

@ -100,11 +100,11 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
VRDPPortMax: b.config.VRDPPortMax,
},
new(vboxcommon.StepAttachFloppy),
&vboxcommon.StepForwardSSH{
CommConfig: &b.config.SSHConfig.Comm,
HostPortMin: b.config.SSHHostPortMin,
HostPortMax: b.config.SSHHostPortMax,
SkipNatMapping: b.config.SSHSkipNatMapping,
&vboxcommon.StepPortForwarding{
CommConfig: &b.config.CommConfig.Comm,
HostPortMin: b.config.HostPortMin,
HostPortMax: b.config.HostPortMax,
SkipNatMapping: b.config.SkipNatMapping,
},
&vboxcommon.StepVBoxManage{
Commands: b.config.VBoxManage,
@ -122,11 +122,11 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
Comm: &b.config.Comm,
},
&communicator.StepConnect{
Config: &b.config.SSHConfig.Comm,
Host: vboxcommon.CommHost(b.config.SSHConfig.Comm.SSHHost),
SSHConfig: b.config.SSHConfig.Comm.SSHConfigFunc(),
SSHPort: vboxcommon.SSHPort,
WinRMPort: vboxcommon.SSHPort,
Config: &b.config.CommConfig.Comm,
Host: vboxcommon.CommHost(b.config.CommConfig.Comm.SSHHost),
SSHConfig: b.config.CommConfig.Comm.SSHConfigFunc(),
SSHPort: vboxcommon.CommPort,
WinRMPort: vboxcommon.CommPort,
},
&vboxcommon.StepUploadVersion{
Path: *b.config.VBoxVersionFile,
@ -138,7 +138,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
},
new(common.StepProvision),
&common.StepCleanupTempKeys{
Comm: &b.config.SSHConfig.Comm,
Comm: &b.config.CommConfig.Comm,
},
&vboxcommon.StepShutdown{
Command: b.config.ShutdownCommand,
@ -158,7 +158,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
Format: b.config.Format,
OutputDir: b.config.OutputDir,
ExportOpts: b.config.ExportConfig.ExportOpts,
SkipNatMapping: b.config.SSHSkipNatMapping,
SkipNatMapping: b.config.SkipNatMapping,
SkipExport: b.config.SkipExport,
},
}

View File

@ -24,7 +24,7 @@ type Config struct {
vboxcommon.ExportConfig `mapstructure:",squash"`
vboxcommon.OutputConfig `mapstructure:",squash"`
vboxcommon.RunConfig `mapstructure:",squash"`
vboxcommon.SSHConfig `mapstructure:",squash"`
vboxcommon.CommConfig `mapstructure:",squash"`
vboxcommon.ShutdownConfig `mapstructure:",squash"`
vboxcommon.VBoxManageConfig `mapstructure:",squash"`
vboxcommon.VBoxVersionConfig `mapstructure:",squash"`
@ -148,7 +148,7 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
errs = packer.MultiErrorAppend(errs, c.OutputConfig.Prepare(&c.ctx, &c.PackerConfig)...)
errs = packer.MultiErrorAppend(errs, c.RunConfig.Prepare(&c.ctx)...)
errs = packer.MultiErrorAppend(errs, c.ShutdownConfig.Prepare(&c.ctx)...)
errs = packer.MultiErrorAppend(errs, c.SSHConfig.Prepare(&c.ctx)...)
errs = packer.MultiErrorAppend(errs, c.CommConfig.Prepare(&c.ctx)...)
errs = packer.MultiErrorAppend(errs, c.VBoxManageConfig.Prepare(&c.ctx)...)
errs = packer.MultiErrorAppend(errs, c.VBoxVersionConfig.Prepare(&c.ctx)...)
errs = packer.MultiErrorAppend(errs, c.BootConfig.Prepare(&c.ctx)...)

View File

@ -72,10 +72,12 @@ type FlatConfig struct {
WinRMUseSSL *bool `mapstructure:"winrm_use_ssl" cty:"winrm_use_ssl"`
WinRMInsecure *bool `mapstructure:"winrm_insecure" cty:"winrm_insecure"`
WinRMUseNTLM *bool `mapstructure:"winrm_use_ntlm" cty:"winrm_use_ntlm"`
HostPortMin *int `mapstructure:"host_port_min" required:"false" cty:"host_port_min"`
HostPortMax *int `mapstructure:"host_port_max" required:"false" cty:"host_port_max"`
SkipNatMapping *bool `mapstructure:"skip_nat_mapping" required:"false" cty:"skip_nat_mapping"`
SSHHostPortMin *int `mapstructure:"ssh_host_port_min" required:"false" cty:"ssh_host_port_min"`
SSHHostPortMax *int `mapstructure:"ssh_host_port_max" cty:"ssh_host_port_max"`
SSHSkipNatMapping *bool `mapstructure:"ssh_skip_nat_mapping" required:"false" cty:"ssh_skip_nat_mapping"`
SSHWaitTimeout *string `mapstructure:"ssh_wait_timeout" cty:"ssh_wait_timeout"`
ShutdownCommand *string `mapstructure:"shutdown_command" required:"false" cty:"shutdown_command"`
ShutdownTimeout *string `mapstructure:"shutdown_timeout" required:"false" cty:"shutdown_timeout"`
PostShutdownDelay *string `mapstructure:"post_shutdown_delay" required:"false" cty:"post_shutdown_delay"`
@ -175,10 +177,12 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec {
"winrm_use_ssl": &hcldec.AttrSpec{Name: "winrm_use_ssl", Type: cty.Bool, Required: false},
"winrm_insecure": &hcldec.AttrSpec{Name: "winrm_insecure", Type: cty.Bool, Required: false},
"winrm_use_ntlm": &hcldec.AttrSpec{Name: "winrm_use_ntlm", Type: cty.Bool, Required: false},
"host_port_min": &hcldec.AttrSpec{Name: "host_port_min", Type: cty.Number, Required: false},
"host_port_max": &hcldec.AttrSpec{Name: "host_port_max", Type: cty.Number, Required: false},
"skip_nat_mapping": &hcldec.AttrSpec{Name: "skip_nat_mapping", Type: cty.Bool, Required: false},
"ssh_host_port_min": &hcldec.AttrSpec{Name: "ssh_host_port_min", Type: cty.Number, Required: false},
"ssh_host_port_max": &hcldec.AttrSpec{Name: "ssh_host_port_max", Type: cty.Number, Required: false},
"ssh_skip_nat_mapping": &hcldec.AttrSpec{Name: "ssh_skip_nat_mapping", Type: cty.Bool, Required: false},
"ssh_wait_timeout": &hcldec.AttrSpec{Name: "ssh_wait_timeout", Type: cty.String, Required: false},
"shutdown_command": &hcldec.AttrSpec{Name: "shutdown_command", Type: cty.String, Required: false},
"shutdown_timeout": &hcldec.AttrSpec{Name: "shutdown_timeout", Type: cty.String, Required: false},
"post_shutdown_delay": &hcldec.AttrSpec{Name: "post_shutdown_delay", Type: cty.String, Required: false},

View File

@ -82,11 +82,11 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
VRDPPortMax: b.config.VRDPPortMax,
},
new(vboxcommon.StepAttachFloppy),
&vboxcommon.StepForwardSSH{
CommConfig: &b.config.SSHConfig.Comm,
HostPortMin: b.config.SSHHostPortMin,
HostPortMax: b.config.SSHHostPortMax,
SkipNatMapping: b.config.SSHSkipNatMapping,
&vboxcommon.StepPortForwarding{
CommConfig: &b.config.CommConfig.Comm,
HostPortMin: b.config.HostPortMin,
HostPortMax: b.config.HostPortMax,
SkipNatMapping: b.config.SkipNatMapping,
},
&vboxcommon.StepVBoxManage{
Commands: b.config.VBoxManage,
@ -104,11 +104,11 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
Comm: &b.config.Comm,
},
&communicator.StepConnect{
Config: &b.config.SSHConfig.Comm,
Host: vboxcommon.CommHost(b.config.SSHConfig.Comm.SSHHost),
SSHConfig: b.config.SSHConfig.Comm.SSHConfigFunc(),
SSHPort: vboxcommon.SSHPort,
WinRMPort: vboxcommon.SSHPort,
Config: &b.config.CommConfig.Comm,
Host: vboxcommon.CommHost(b.config.CommConfig.Comm.SSHHost),
SSHConfig: b.config.CommConfig.Comm.SSHConfigFunc(),
SSHPort: vboxcommon.CommPort,
WinRMPort: vboxcommon.CommPort,
},
&vboxcommon.StepUploadVersion{
Path: *b.config.VBoxVersionFile,
@ -120,7 +120,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
},
new(common.StepProvision),
&common.StepCleanupTempKeys{
Comm: &b.config.SSHConfig.Comm,
Comm: &b.config.CommConfig.Comm,
},
&vboxcommon.StepShutdown{
Command: b.config.ShutdownCommand,
@ -141,7 +141,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
Format: b.config.Format,
OutputDir: b.config.OutputDir,
ExportOpts: b.config.ExportOpts,
SkipNatMapping: b.config.SSHSkipNatMapping,
SkipNatMapping: b.config.SkipNatMapping,
SkipExport: b.config.SkipExport,
},
}

View File

@ -25,7 +25,7 @@ type Config struct {
vboxcommon.ExportConfig `mapstructure:",squash"`
vboxcommon.OutputConfig `mapstructure:",squash"`
vboxcommon.RunConfig `mapstructure:",squash"`
vboxcommon.SSHConfig `mapstructure:",squash"`
vboxcommon.CommConfig `mapstructure:",squash"`
vboxcommon.ShutdownConfig `mapstructure:",squash"`
vboxcommon.VBoxManageConfig `mapstructure:",squash"`
vboxcommon.VBoxVersionConfig `mapstructure:",squash"`
@ -83,7 +83,7 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
errs = packer.MultiErrorAppend(errs, c.OutputConfig.Prepare(&c.ctx, &c.PackerConfig)...)
errs = packer.MultiErrorAppend(errs, c.RunConfig.Prepare(&c.ctx)...)
errs = packer.MultiErrorAppend(errs, c.ShutdownConfig.Prepare(&c.ctx)...)
errs = packer.MultiErrorAppend(errs, c.SSHConfig.Prepare(&c.ctx)...)
errs = packer.MultiErrorAppend(errs, c.CommConfig.Prepare(&c.ctx)...)
errs = packer.MultiErrorAppend(errs, c.VBoxManageConfig.Prepare(&c.ctx)...)
errs = packer.MultiErrorAppend(errs, c.VBoxVersionConfig.Prepare(&c.ctx)...)
errs = packer.MultiErrorAppend(errs, c.BootConfig.Prepare(&c.ctx)...)

View File

@ -72,10 +72,12 @@ type FlatConfig struct {
WinRMUseSSL *bool `mapstructure:"winrm_use_ssl" cty:"winrm_use_ssl"`
WinRMInsecure *bool `mapstructure:"winrm_insecure" cty:"winrm_insecure"`
WinRMUseNTLM *bool `mapstructure:"winrm_use_ntlm" cty:"winrm_use_ntlm"`
HostPortMin *int `mapstructure:"host_port_min" required:"false" cty:"host_port_min"`
HostPortMax *int `mapstructure:"host_port_max" required:"false" cty:"host_port_max"`
SkipNatMapping *bool `mapstructure:"skip_nat_mapping" required:"false" cty:"skip_nat_mapping"`
SSHHostPortMin *int `mapstructure:"ssh_host_port_min" required:"false" cty:"ssh_host_port_min"`
SSHHostPortMax *int `mapstructure:"ssh_host_port_max" cty:"ssh_host_port_max"`
SSHSkipNatMapping *bool `mapstructure:"ssh_skip_nat_mapping" required:"false" cty:"ssh_skip_nat_mapping"`
SSHWaitTimeout *string `mapstructure:"ssh_wait_timeout" cty:"ssh_wait_timeout"`
ShutdownCommand *string `mapstructure:"shutdown_command" required:"false" cty:"shutdown_command"`
ShutdownTimeout *string `mapstructure:"shutdown_timeout" required:"false" cty:"shutdown_timeout"`
PostShutdownDelay *string `mapstructure:"post_shutdown_delay" required:"false" cty:"post_shutdown_delay"`
@ -171,10 +173,12 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec {
"winrm_use_ssl": &hcldec.AttrSpec{Name: "winrm_use_ssl", Type: cty.Bool, Required: false},
"winrm_insecure": &hcldec.AttrSpec{Name: "winrm_insecure", Type: cty.Bool, Required: false},
"winrm_use_ntlm": &hcldec.AttrSpec{Name: "winrm_use_ntlm", Type: cty.Bool, Required: false},
"host_port_min": &hcldec.AttrSpec{Name: "host_port_min", Type: cty.Number, Required: false},
"host_port_max": &hcldec.AttrSpec{Name: "host_port_max", Type: cty.Number, Required: false},
"skip_nat_mapping": &hcldec.AttrSpec{Name: "skip_nat_mapping", Type: cty.Bool, Required: false},
"ssh_host_port_min": &hcldec.AttrSpec{Name: "ssh_host_port_min", Type: cty.Number, Required: false},
"ssh_host_port_max": &hcldec.AttrSpec{Name: "ssh_host_port_max", Type: cty.Number, Required: false},
"ssh_skip_nat_mapping": &hcldec.AttrSpec{Name: "ssh_skip_nat_mapping", Type: cty.Bool, Required: false},
"ssh_wait_timeout": &hcldec.AttrSpec{Name: "ssh_wait_timeout", Type: cty.String, Required: false},
"shutdown_command": &hcldec.AttrSpec{Name: "shutdown_command", Type: cty.String, Required: false},
"shutdown_timeout": &hcldec.AttrSpec{Name: "shutdown_timeout", Type: cty.String, Required: false},
"post_shutdown_delay": &hcldec.AttrSpec{Name: "post_shutdown_delay", Type: cty.String, Required: false},

View File

@ -3,8 +3,6 @@
package common
import (
"time"
"github.com/hashicorp/packer/helper/communicator"
"github.com/hashicorp/packer/template/interpolate"
)
@ -15,16 +13,9 @@ type SSHConfig struct {
// These are deprecated, but we keep them around for BC
// TODO(@mitchellh): remove
SSHSkipRequestPty bool `mapstructure:"ssh_skip_request_pty"`
// These are deprecated, but we keep them around for BC
// TODO(@mitchellh): remove
SSHWaitTimeout time.Duration `mapstructure:"ssh_wait_timeout"`
}
func (c *SSHConfig) Prepare(ctx *interpolate.Context) []error {
// TODO: backwards compatibility, write fixer instead
if c.SSHWaitTimeout != 0 {
c.Comm.SSHTimeout = c.SSHWaitTimeout
}
if c.SSHSkipRequestPty {
c.Comm.SSHPty = false
}

View File

@ -103,7 +103,6 @@ type FlatConfig struct {
WinRMInsecure *bool `mapstructure:"winrm_insecure" cty:"winrm_insecure"`
WinRMUseNTLM *bool `mapstructure:"winrm_use_ntlm" cty:"winrm_use_ntlm"`
SSHSkipRequestPty *bool `mapstructure:"ssh_skip_request_pty" cty:"ssh_skip_request_pty"`
SSHWaitTimeout *string `mapstructure:"ssh_wait_timeout" cty:"ssh_wait_timeout"`
ToolsUploadFlavor *string `mapstructure:"tools_upload_flavor" required:"false" cty:"tools_upload_flavor"`
ToolsUploadPath *string `mapstructure:"tools_upload_path" required:"false" cty:"tools_upload_path"`
VMXData map[string]string `mapstructure:"vmx_data" required:"false" cty:"vmx_data"`
@ -234,7 +233,6 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec {
"winrm_insecure": &hcldec.AttrSpec{Name: "winrm_insecure", Type: cty.Bool, Required: false},
"winrm_use_ntlm": &hcldec.AttrSpec{Name: "winrm_use_ntlm", Type: cty.Bool, Required: false},
"ssh_skip_request_pty": &hcldec.AttrSpec{Name: "ssh_skip_request_pty", Type: cty.Bool, Required: false},
"ssh_wait_timeout": &hcldec.AttrSpec{Name: "ssh_wait_timeout", Type: cty.String, Required: false},
"tools_upload_flavor": &hcldec.AttrSpec{Name: "tools_upload_flavor", Type: cty.String, Required: false},
"tools_upload_path": &hcldec.AttrSpec{Name: "tools_upload_path", Type: cty.String, Required: false},
"vmx_data": &hcldec.BlockAttrsSpec{TypeName: "vmx_data", ElementType: cty.String, Required: false},

View File

@ -87,7 +87,6 @@ type FlatConfig struct {
WinRMInsecure *bool `mapstructure:"winrm_insecure" cty:"winrm_insecure"`
WinRMUseNTLM *bool `mapstructure:"winrm_use_ntlm" cty:"winrm_use_ntlm"`
SSHSkipRequestPty *bool `mapstructure:"ssh_skip_request_pty" cty:"ssh_skip_request_pty"`
SSHWaitTimeout *string `mapstructure:"ssh_wait_timeout" cty:"ssh_wait_timeout"`
ToolsUploadFlavor *string `mapstructure:"tools_upload_flavor" required:"false" cty:"tools_upload_flavor"`
ToolsUploadPath *string `mapstructure:"tools_upload_path" required:"false" cty:"tools_upload_path"`
VMXData map[string]string `mapstructure:"vmx_data" required:"false" cty:"vmx_data"`
@ -194,7 +193,6 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec {
"winrm_insecure": &hcldec.AttrSpec{Name: "winrm_insecure", Type: cty.Bool, Required: false},
"winrm_use_ntlm": &hcldec.AttrSpec{Name: "winrm_use_ntlm", Type: cty.Bool, Required: false},
"ssh_skip_request_pty": &hcldec.AttrSpec{Name: "ssh_skip_request_pty", Type: cty.Bool, Required: false},
"ssh_wait_timeout": &hcldec.AttrSpec{Name: "ssh_wait_timeout", Type: cty.String, Required: false},
"tools_upload_flavor": &hcldec.AttrSpec{Name: "tools_upload_flavor", Type: cty.String, Required: false},
"tools_upload_path": &hcldec.AttrSpec{Name: "tools_upload_path", Type: cty.String, Required: false},
"vmx_data": &hcldec.BlockAttrsSpec{TypeName: "vmx_data", ElementType: cty.String, Required: false},

View File

@ -46,6 +46,8 @@ func init() {
"spot-price-auto-product": new(FixerAmazonSpotPriceProductDeprecation),
"qemu-disk-size": new(FixerQEMUDiskSize),
"galaxy-command": new(FixerGalaxyCommand),
"comm-config": new(FixerCommConfig),
"ssh-wait-timeout": new(FixerSSHTimout),
}
FixerOrder = []string{
@ -75,5 +77,7 @@ func init() {
"spot-price-auto-product",
"qemu-disk-size",
"galaxy-command",
"comm-config",
"ssh-wait-timeout",
}
}

102
fix/fixer_comm_config.go Normal file
View File

@ -0,0 +1,102 @@
package fix
import (
"strings"
"github.com/mitchellh/mapstructure"
)
// FixerCommConfig removes ssh prefix from communicator port forwarding config
// for variables host_port_min, host_port_max, skip_nat_mapping
type FixerCommConfig struct{}
func (FixerCommConfig) Fix(input map[string]interface{}) (map[string]interface{}, error) {
type template struct {
Builders []interface{}
}
// Decode the input into our structure, if we can
var tpl template
if err := mapstructure.WeakDecode(input, &tpl); err != nil {
return nil, err
}
for i, raw := range tpl.Builders {
var builders map[string]interface{}
if err := mapstructure.Decode(raw, &builders); err != nil {
// Ignore errors, could be a non-map
continue
}
// only virtualbox builders
builderType := builders["type"].(string)
if ok := strings.HasPrefix(builderType, "virtualbox"); !ok {
continue
}
// ssh_host_port_min to host_port_min
if _, ok := builders["host_port_min"]; ok {
// drop ssh_host_port_min if it is also included
if _, sshHostPortMinIncluded := builders["ssh_host_port_min"]; sshHostPortMinIncluded {
delete(builders, "ssh_host_port_min")
}
} else if _, ok := builders["ssh_host_port_min"]; ok {
// replace ssh_host_port_min with host_port_min
sshHostPortMinRaw, _ := builders["ssh_host_port_min"]
delete(builders, "ssh_host_port_min")
builders["host_port_min"] = sshHostPortMinRaw
}
// ssh_host_port_max to host_port_max
if _, ok := builders["host_port_max"]; ok {
// drop ssh_host_port_max if it is also included
if _, sshHostPortMaxIncluded := builders["ssh_host_port_max"]; sshHostPortMaxIncluded {
delete(builders, "ssh_host_port_max")
}
} else if _, ok := builders["ssh_host_port_max"]; ok {
// replace ssh_host_port_max with host_port_max
sshHostPortMaxRaw, _ := builders["ssh_host_port_max"]
delete(builders, "ssh_host_port_max")
builders["host_port_max"] = sshHostPortMaxRaw
}
// ssh_skip_nat_mapping to skip_nat_mapping
if _, ok := builders["skip_nat_mapping"]; ok {
// drop ssh_skip_nat_mapping if it is also included
if _, sshSkipNatMappingIncluded := builders["ssh_skip_nat_mapping"]; sshSkipNatMappingIncluded {
delete(builders, "ssh_skip_nat_mapping")
}
} else if _, ok := builders["ssh_skip_nat_mapping"]; ok {
// replace ssh_skip_nat_mapping with skip_nat_mapping
sshSkipNatMappingRaw, _ := builders["ssh_skip_nat_mapping"]
sshSkipNatMappingBool, ok := sshSkipNatMappingRaw.(bool)
if ok {
delete(builders, "ssh_skip_nat_mapping")
builders["skip_nat_mapping"] = sshSkipNatMappingBool
}
}
// Write all changes back to template
tpl.Builders[i] = builders
}
if len(tpl.Builders) > 0 {
input["builders"] = tpl.Builders
}
return input, nil
}
func (FixerCommConfig) Synopsis() string {
return `Remove ssh prefixes from communicator port forwarding configuration (host_port_min, host_port_max, skip_nat_mapping)`
}

View File

@ -0,0 +1,161 @@
package fix
import (
"reflect"
"testing"
)
func TestFixerCommConfig_Impl(t *testing.T) {
var _ Fixer = new(FixerCommConfig)
}
func TestFixerCommConfig_Fix(t *testing.T) {
cases := []struct {
Input map[string]interface{}
Expected map[string]interface{}
}{
// set host_port_min
{
Input: map[string]interface{}{
"type": "virtualbox-iso",
"host_port_min": 2222,
},
Expected: map[string]interface{}{
"type": "virtualbox-iso",
"host_port_min": 2222,
},
},
// set ssh_host_port_min (old key)
{
Input: map[string]interface{}{
"type": "virtualbox-ovf",
"ssh_host_port_min": 2222,
},
Expected: map[string]interface{}{
"type": "virtualbox-ovf",
"host_port_min": 2222,
},
},
// set ssh_host_port_min and host_port_min
// host_port_min takes precedence
{
Input: map[string]interface{}{
"type": "virtualbox-vm",
"ssh_host_port_min": 1234,
"host_port_min": 4321,
},
Expected: map[string]interface{}{
"type": "virtualbox-vm",
"host_port_min": 4321,
},
},
// set host_port_max
{
Input: map[string]interface{}{
"type": "virtualbox-iso",
"host_port_max": 4444,
},
Expected: map[string]interface{}{
"type": "virtualbox-iso",
"host_port_max": 4444,
},
},
// set ssh_host_port_max (old key)
{
Input: map[string]interface{}{
"type": "virtualbox-iso",
"ssh_host_port_max": 4444,
},
Expected: map[string]interface{}{
"type": "virtualbox-iso",
"host_port_max": 4444,
},
},
// set ssh_host_port_max and host_port_max
// host_port_max takes precedence
{
Input: map[string]interface{}{
"type": "virtualbox-vm",
"ssh_host_port_max": 1234,
"host_port_max": 4321,
},
Expected: map[string]interface{}{
"type": "virtualbox-vm",
"host_port_max": 4321,
},
},
// set skip_nat_mapping
{
Input: map[string]interface{}{
"type": "virtualbox-vm",
"skip_nat_mapping": true,
},
Expected: map[string]interface{}{
"type": "virtualbox-vm",
"skip_nat_mapping": true,
},
},
// set ssh_skip_nat_mapping (old key)
{
Input: map[string]interface{}{
"type": "virtualbox-vm",
"ssh_skip_nat_mapping": true,
},
Expected: map[string]interface{}{
"type": "virtualbox-vm",
"skip_nat_mapping": true,
},
},
// set ssh_skip_nat_mapping and skip_nat_mapping
// skip_nat_mapping takes precedence
{
Input: map[string]interface{}{
"type": "virtualbox-iso",
"ssh_skip_nat_mapping": false,
"skip_nat_mapping": true,
},
Expected: map[string]interface{}{
"type": "virtualbox-iso",
"skip_nat_mapping": true,
},
},
}
for _, tc := range cases {
var f FixerCommConfig
input := map[string]interface{}{
"builders": []interface{}{tc.Input},
}
expected := map[string]interface{}{
"builders": []interface{}{tc.Expected},
}
output, err := f.Fix(input)
if err != nil {
t.Fatalf("err: %s", err)
}
if !reflect.DeepEqual(output, expected) {
t.Fatalf("unexpected: %#v\nexpected: %#v\n", output, expected)
}
}
}

65
fix/fixer_ssh_timeout.go Normal file
View File

@ -0,0 +1,65 @@
package fix
import (
"github.com/mitchellh/mapstructure"
)
// FixerSSHTimout replaces ssh_wait_timeout with ssh_timeout
type FixerSSHTimout struct{}
func (FixerSSHTimout) Fix(input map[string]interface{}) (map[string]interface{}, error) {
type template struct {
Builders []interface{}
}
// Decode the input into our structure, if we can
var tpl template
if err := mapstructure.WeakDecode(input, &tpl); err != nil {
return nil, err
}
for i, raw := range tpl.Builders {
var builders map[string]interface{}
if err := mapstructure.Decode(raw, &builders); err != nil {
// Ignore errors, could be a non-map
continue
}
if _, ok := builders["ssh_timeout"]; ok {
// drop ssh_wait_timeout if it is also included
if _, sshWaitTimeoutIncluded := builders["ssh_wait_timeout"]; sshWaitTimeoutIncluded {
delete(builders, "ssh_wait_timeout")
}
} else {
// replace ssh_wait_timeout with ssh_timeout if it exists
sshWaitTimeoutRaw, ok := builders["ssh_wait_timeout"]
if !ok {
continue
}
sshWaitTimeoutString, ok := sshWaitTimeoutRaw.(string)
if !ok {
continue
}
delete(builders, "ssh_wait_timeout")
builders["ssh_timeout"] = sshWaitTimeoutString
}
// Write all changes back to template
tpl.Builders[i] = builders
}
if len(tpl.Builders) > 0 {
input["builders"] = tpl.Builders
}
return input, nil
}
func (FixerSSHTimout) Synopsis() string {
return `Replaces "ssh_wait_timeout" with "ssh_timeout"`
}

View File

@ -0,0 +1,73 @@
package fix
import (
"reflect"
"testing"
)
func TestFixerSSHTimout_Impl(t *testing.T) {
var _ Fixer = new(FixerSSHTimout)
}
func TestFixerSSHTimout_Fix(t *testing.T) {
cases := []struct {
Input map[string]interface{}
Expected map[string]interface{}
}{
// set galaxy_command
{
Input: map[string]interface{}{
"ssh_timeout": "1h5m2s",
},
Expected: map[string]interface{}{
"ssh_timeout": "1h5m2s",
},
},
// set galaxycommand (old key)
{
Input: map[string]interface{}{
"ssh_wait_timeout": "1h5m2s",
},
Expected: map[string]interface{}{
"ssh_timeout": "1h5m2s",
},
},
// set galaxy_command and galaxycommand
// galaxy_command takes precedence
{
Input: map[string]interface{}{
"ssh_timeout": "1h5m2s",
"ssh_wait_timeout": "30m",
},
Expected: map[string]interface{}{
"ssh_timeout": "1h5m2s",
},
},
}
for _, tc := range cases {
var f FixerSSHTimout
input := map[string]interface{}{
"builders": []interface{}{tc.Input},
}
expected := map[string]interface{}{
"builders": []interface{}{tc.Expected},
}
output, err := f.Fix(input)
if err != nil {
t.Fatalf("err: %s", err)
}
if !reflect.DeepEqual(output, expected) {
t.Fatalf("unexpected: %#v\nexpected: %#v\n", output, expected)
}
}
}

View File

@ -136,11 +136,11 @@ necessary for this build to succeed and can be found further down the page.
#### Optional common fields:
<%= partial "partials/helper/communicator/Config-not-required" %>
<%= partial "partials/builder/virtualbox/common/CommConfig-not-required" %>
#### Optional SSH fields:
<%= partial "partials/helper/communicator/SSH-not-required" %>
<%= partial "partials/builder/virtualbox/common/SSHConfig-not-required" %>
#### Optional WinRM fields:

View File

@ -122,11 +122,11 @@ necessary for this build to succeed and can be found further down the page.
#### Optional common fields:
<%= partial "partials/helper/communicator/Config-not-required" %>
<%= partial "partials/builder/virtualbox/common/CommConfig-not-required" %>
#### Optional SSH fields:
<%= partial "partials/helper/communicator/SSH-not-required" %>
<%= partial "partials/builder/virtualbox/common/SSHConfig-not-required" %>
#### Optional WinRM fields:

View File

@ -225,15 +225,7 @@ builder.
not export the VM. Useful if the builder should be applied again on the created
target snapshot.
- `ssh_host_port_min` and `ssh_host_port_max` (number) - The minimum and
maximum port to use for the SSH port on the host machine which is forwarded
to the SSH port on the guest machine. Because Packer often runs in parallel,
Packer will choose a randomly available port in this range to use as the
host port. By default this is `2222` to `4444`.
- `ssh_skip_nat_mapping` (boolean) - Defaults to `false`. When enabled, Packer
does not setup forwarded port mapping for SSH requests and uses `ssh_port`
on the host to communicate to the virtual machine.
<%= partial "partials/builder/virtualbox/common/CommConfig-not-required" %>
- `target_snapshot` (string) - Default to `null/empty`. The name of the
snapshot which shall be created after all provisioners has been run by the

View File

@ -0,0 +1,14 @@
<!-- Code generated from the comments of the CommConfig struct in builder/virtualbox/common/comm_config.go; DO NOT EDIT MANUALLY -->
- `host_port_min` (int) - The minimum port to use for the Communicator port on the host machine which is forwarded
to the SSH or WinRM port on the guest machine. By default this is 2222.
- `host_port_max` (int) - The maximum port to use for the Communicator port on the host machine which is forwarded
to the SSH or WinRM port on the guest machine. Because Packer often runs in parallel,
Packer will choose a randomly available port in this range to use as the
host port. By default this is 4444.
- `skip_nat_mapping` (bool) - Defaults to false. When enabled, Packer
does not setup forwarded port mapping for communicator (SSH or WinRM) requests and uses ssh_port or winrm_port
on the host to communicate to the virtual machine.

View File

@ -1,13 +0,0 @@
<!-- Code generated from the comments of the SSHConfig struct in builder/virtualbox/common/ssh_config.go; DO NOT EDIT MANUALLY -->
- `ssh_host_port_min` (int) - The minimum and
maximum port to use for the SSH port on the host machine which is forwarded
to the SSH port on the guest machine. Because Packer often runs in parallel,
Packer will choose a randomly available port in this range to use as the
host port. By default this is 2222 to 4444.
- `ssh_host_port_max` (int) - SSH Host Port Max
- `ssh_skip_nat_mapping` (bool) - Defaults to false. When enabled, Packer
does not setup forwarded port mapping for SSH requests and uses ssh_port
on the host to communicate to the virtual machine.