2019-10-14 10:43:59 -04:00
|
|
|
//go:generate mapstructure-to-hcl2 -type Config
|
|
|
|
|
2014-03-24 06:20:32 -04:00
|
|
|
package null
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-06-13 14:07:43 -04:00
|
|
|
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/common"
|
|
|
|
"github.com/hashicorp/packer/helper/communicator"
|
|
|
|
"github.com/hashicorp/packer/helper/config"
|
|
|
|
"github.com/hashicorp/packer/packer"
|
|
|
|
"github.com/hashicorp/packer/template/interpolate"
|
2014-03-24 06:20:32 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
common.PackerConfig `mapstructure:",squash"`
|
|
|
|
|
2015-06-13 17:42:43 -04:00
|
|
|
CommConfig communicator.Config `mapstructure:",squash"`
|
2014-03-24 06:20:32 -04:00
|
|
|
}
|
|
|
|
|
2019-12-17 05:25:56 -05:00
|
|
|
func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
|
2014-03-24 06:20:32 -04:00
|
|
|
|
2020-01-15 17:27:55 -05:00
|
|
|
err := config.Decode(c, &config.DecodeOpts{
|
2015-06-13 17:42:43 -04:00
|
|
|
Interpolate: true,
|
|
|
|
InterpolateFilter: &interpolate.RenderFilter{},
|
2015-05-27 15:59:14 -04:00
|
|
|
}, raws...)
|
2014-03-24 06:20:32 -04:00
|
|
|
if err != nil {
|
2019-12-17 05:25:56 -05:00
|
|
|
return nil, err
|
2014-03-24 06:20:32 -04:00
|
|
|
}
|
|
|
|
|
2015-05-27 15:59:14 -04:00
|
|
|
var errs *packer.MultiError
|
2015-06-13 17:42:43 -04:00
|
|
|
if es := c.CommConfig.Prepare(nil); len(es) > 0 {
|
|
|
|
errs = packer.MultiErrorAppend(errs, es...)
|
|
|
|
}
|
2014-03-24 06:20:32 -04:00
|
|
|
|
2017-03-05 17:22:33 -05:00
|
|
|
if c.CommConfig.Type != "none" {
|
|
|
|
if c.CommConfig.Host() == "" {
|
|
|
|
errs = packer.MultiErrorAppend(errs,
|
|
|
|
fmt.Errorf("a Host must be specified, please reference your communicator documentation"))
|
|
|
|
}
|
2014-03-24 06:20:32 -04:00
|
|
|
|
2017-03-05 17:22:33 -05:00
|
|
|
if c.CommConfig.User() == "" {
|
|
|
|
errs = packer.MultiErrorAppend(errs,
|
|
|
|
fmt.Errorf("a Username must be specified, please reference your communicator documentation"))
|
|
|
|
}
|
|
|
|
|
2018-08-23 10:35:07 -04:00
|
|
|
if !c.CommConfig.SSHAgentAuth && c.CommConfig.Password() == "" && c.CommConfig.SSHPrivateKeyFile == "" {
|
2017-03-05 17:22:33 -05:00
|
|
|
errs = packer.MultiErrorAppend(errs,
|
|
|
|
fmt.Errorf("one authentication method must be specified, please reference your communicator documentation"))
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c.CommConfig.SSHAgentAuth &&
|
2018-08-23 10:35:07 -04:00
|
|
|
(c.CommConfig.SSHPassword != "" || c.CommConfig.SSHPrivateKeyFile != "")) ||
|
|
|
|
(c.CommConfig.SSHPassword != "" && c.CommConfig.SSHPrivateKeyFile != "") {
|
2017-03-05 17:22:33 -05:00
|
|
|
errs = packer.MultiErrorAppend(errs,
|
|
|
|
fmt.Errorf("only one of ssh_agent_auth, ssh_password, and ssh_private_key_file must be specified"))
|
2014-03-24 06:20:32 -04:00
|
|
|
|
2017-03-05 17:22:33 -05:00
|
|
|
}
|
2014-03-24 06:20:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if errs != nil && len(errs.Errors) > 0 {
|
2019-12-17 05:25:56 -05:00
|
|
|
return nil, errs
|
2014-03-24 06:20:32 -04:00
|
|
|
}
|
|
|
|
|
2019-12-17 05:25:56 -05:00
|
|
|
return nil, nil
|
2014-03-24 06:20:32 -04:00
|
|
|
}
|