2014-03-24 06:20:32 -04:00
|
|
|
package null
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-06-13 14:07:43 -04:00
|
|
|
|
2014-03-24 06:20:32 -04:00
|
|
|
"github.com/mitchellh/packer/common"
|
2015-06-13 17:42:43 -04:00
|
|
|
"github.com/mitchellh/packer/helper/communicator"
|
2015-05-27 15:59:14 -04:00
|
|
|
"github.com/mitchellh/packer/helper/config"
|
2014-03-24 06:20:32 -04:00
|
|
|
"github.com/mitchellh/packer/packer"
|
2015-05-27 15:59:14 -04:00
|
|
|
"github.com/mitchellh/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
|
|
|
}
|
|
|
|
|
|
|
|
func NewConfig(raws ...interface{}) (*Config, []string, error) {
|
2015-06-13 14:07:43 -04:00
|
|
|
var c Config
|
2014-03-24 06:20:32 -04:00
|
|
|
|
2015-06-13 14:07:43 -04: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 {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
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...)
|
|
|
|
}
|
|
|
|
if c.CommConfig.SSHHost == "" {
|
2014-03-24 06:20:32 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs,
|
|
|
|
fmt.Errorf("host must be specified"))
|
|
|
|
}
|
|
|
|
|
2015-06-13 17:42:43 -04:00
|
|
|
if c.CommConfig.SSHUsername == "" {
|
2014-03-24 06:20:32 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs,
|
|
|
|
fmt.Errorf("ssh_username must be specified"))
|
|
|
|
}
|
|
|
|
|
2015-06-13 17:42:43 -04:00
|
|
|
if c.CommConfig.SSHPassword == "" && c.CommConfig.SSHPrivateKey == "" {
|
2014-03-24 06:20:32 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs,
|
|
|
|
fmt.Errorf("one of ssh_password and ssh_private_key_file must be specified"))
|
|
|
|
}
|
|
|
|
|
2015-06-13 17:42:43 -04:00
|
|
|
if c.CommConfig.SSHPassword != "" && c.CommConfig.SSHPrivateKey != "" {
|
2014-03-24 06:20:32 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs,
|
|
|
|
fmt.Errorf("only one of ssh_password and ssh_private_key_file must be specified"))
|
|
|
|
}
|
|
|
|
|
|
|
|
if errs != nil && len(errs.Errors) > 0 {
|
|
|
|
return nil, nil, errs
|
|
|
|
}
|
|
|
|
|
2015-06-13 14:07:43 -04:00
|
|
|
return &c, nil, nil
|
2014-03-24 06:20:32 -04:00
|
|
|
}
|