diff --git a/builder/null/builder.go b/builder/null/builder.go index fed303540..949c01c2b 100644 --- a/builder/null/builder.go +++ b/builder/null/builder.go @@ -30,7 +30,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe steps := []multistep.Step{ &communicator.StepConnect{ Config: &b.config.CommConfig, - Host: CommHost(b.config.CommConfig.SSHHost), + Host: CommHost(b.config.CommConfig.Host()), SSHConfig: SSHConfig( b.config.CommConfig.SSHUsername, b.config.CommConfig.SSHPassword, diff --git a/builder/null/config.go b/builder/null/config.go index c207f8087..697d40ce9 100644 --- a/builder/null/config.go +++ b/builder/null/config.go @@ -31,19 +31,19 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { if es := c.CommConfig.Prepare(nil); len(es) > 0 { errs = packer.MultiErrorAppend(errs, es...) } - if c.CommConfig.SSHHost == "" { + if c.CommConfig.Host() == "" { errs = packer.MultiErrorAppend(errs, - fmt.Errorf("ssh_host must be specified")) + fmt.Errorf("a Host must be specified, please reference your communicator documentation")) } - if c.CommConfig.SSHUsername == "" { + if c.CommConfig.User() == "" { errs = packer.MultiErrorAppend(errs, - fmt.Errorf("ssh_username must be specified")) + fmt.Errorf("a Username must be specified, please reference your communicator documentation")) } - if c.CommConfig.SSHPassword == "" && c.CommConfig.SSHPrivateKey == "" { + if c.CommConfig.Password() == "" && c.CommConfig.SSHPrivateKey == "" { errs = packer.MultiErrorAppend(errs, - fmt.Errorf("one of ssh_password and ssh_private_key_file must be specified")) + fmt.Errorf("one authentication method must be specified, please reference your communicator documentation")) } if c.CommConfig.SSHPassword != "" && c.CommConfig.SSHPrivateKey != "" { diff --git a/helper/communicator/config.go b/helper/communicator/config.go index ad90d5e9c..7c36e70d9 100644 --- a/helper/communicator/config.go +++ b/helper/communicator/config.go @@ -55,6 +55,42 @@ func (c *Config) Port() int { } } +// Host returns the port that will be used for access based on config. +func (c *Config) Host() string { + switch c.Type { + case "ssh": + return c.SSHHost + case "winrm": + return c.WinRMHost + default: + return "" + } +} + +// User returns the port that will be used for access based on config. +func (c *Config) User() string { + switch c.Type { + case "ssh": + return c.SSHUsername + case "winrm": + return c.WinRMUser + default: + return "" + } +} + +// Password returns the port that will be used for access based on config. +func (c *Config) Password() string { + switch c.Type { + case "ssh": + return c.SSHPassword + case "winrm": + return c.WinRMPassword + default: + return "" + } +} + func (c *Config) Prepare(ctx *interpolate.Context) []error { if c.Type == "" { c.Type = "ssh"