builder/null: interpolations

This commit is contained in:
Mitchell Hashimoto 2015-05-27 12:59:14 -07:00
parent 5aa30caa64
commit 31bdb4853c
1 changed files with 12 additions and 28 deletions

View File

@ -3,7 +3,9 @@ package null
import ( import (
"fmt" "fmt"
"github.com/mitchellh/packer/common" "github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/template/interpolate"
) )
type Config struct { type Config struct {
@ -14,46 +16,28 @@ type Config struct {
SSHUsername string `mapstructure:"ssh_username"` SSHUsername string `mapstructure:"ssh_username"`
SSHPassword string `mapstructure:"ssh_password"` SSHPassword string `mapstructure:"ssh_password"`
SSHPrivateKeyFile string `mapstructure:"ssh_private_key_file"` SSHPrivateKeyFile string `mapstructure:"ssh_private_key_file"`
tpl *packer.ConfigTemplate
} }
func NewConfig(raws ...interface{}) (*Config, []string, error) { func NewConfig(raws ...interface{}) (*Config, []string, error) {
c := new(Config) c := new(Config)
md, err := common.DecodeConfig(c, raws...)
err := config.Decode(&c, &config.DecodeOpts{
Interpolate: true,
InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{
"run_command",
},
},
}, raws...)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
c.tpl, err = packer.NewConfigTemplate()
if err != nil {
return nil, nil, err
}
c.tpl.UserVars = c.PackerUserVars
if c.Port == 0 { if c.Port == 0 {
c.Port = 22 c.Port = 22
} }
errs := common.CheckUnusedConfig(md) var errs *packer.MultiError
templates := map[string]*string{
"host": &c.Host,
"ssh_username": &c.SSHUsername,
"ssh_password": &c.SSHPassword,
"ssh_private_key_file": &c.SSHPrivateKeyFile,
}
for n, ptr := range templates {
var err error
*ptr, err = c.tpl.Process(*ptr, nil)
if err != nil {
errs = packer.MultiErrorAppend(
errs, fmt.Errorf("Error processing %s: %s", n, err))
}
}
if c.Host == "" { if c.Host == "" {
errs = packer.MultiErrorAppend(errs, errs = packer.MultiErrorAppend(errs,
fmt.Errorf("host must be specified")) fmt.Errorf("host must be specified"))