add an extra string array to the Prepare() return values in the builder interfaces; this sets up the ability for builders to give the provisioners custom user-accessible build-time variables.

This commit is contained in:
Megan Marsh 2019-12-16 21:23:05 -08:00
parent 18bb4ffb44
commit 0f6d1beccf
93 changed files with 592 additions and 533 deletions

View File

@ -41,7 +41,7 @@ const (
ALICLOUD_DEFAULT_LONG_TIMEOUT = 3600
)
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
err := config.Decode(&b.config, &config.DecodeOpts{
Interpolate: true,
InterpolateContext: &b.config.ctx,
@ -53,7 +53,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}, raws...)
b.config.ctx.EnableEnv = true
if err != nil {
return nil, err
return nil, nil, err
}
if b.config.PackerConfig.PackerForce {
@ -68,11 +68,11 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare(&b.config.ctx)...)
if errs != nil && len(errs.Errors) > 0 {
return nil, errs
return nil, nil, errs
}
packer.LogSecretFilter.Set(b.config.AlicloudAccessKey, b.config.AlicloudSecretKey)
return nil, nil
return nil, nil, nil
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

View File

@ -35,7 +35,7 @@ func TestBuilder_Prepare_BadType(t *testing.T) {
"access_key": []string{},
}
warnings, err := b.Prepare(c)
_, warnings, err := b.Prepare(c)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -50,7 +50,7 @@ func TestBuilderPrepare_ECSImageName(t *testing.T) {
// Test good
config["image_name"] = "ecs.n1.tiny"
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -61,7 +61,7 @@ func TestBuilderPrepare_ECSImageName(t *testing.T) {
// Test bad
config["ecs_image_name"] = "foo {{"
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -72,7 +72,7 @@ func TestBuilderPrepare_ECSImageName(t *testing.T) {
// Test bad
delete(config, "image_name")
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -87,7 +87,7 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) {
// Add a random key
config["i_should_not_be_valid"] = true
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -120,7 +120,7 @@ func TestBuilderPrepare_Devices(t *testing.T) {
"disk_device": "/dev/xvdc",
},
}
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -160,7 +160,7 @@ func TestBuilderPrepare_IgnoreDataDisks(t *testing.T) {
var b Builder
config := testBuilderConfig()
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -173,7 +173,7 @@ func TestBuilderPrepare_IgnoreDataDisks(t *testing.T) {
}
config["image_ignore_data_disks"] = "false"
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -186,7 +186,7 @@ func TestBuilderPrepare_IgnoreDataDisks(t *testing.T) {
}
config["image_ignore_data_disks"] = "true"
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -203,7 +203,7 @@ func TestBuilderPrepare_WaitSnapshotReadyTimeout(t *testing.T) {
var b Builder
config := testBuilderConfig()
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -219,7 +219,7 @@ func TestBuilderPrepare_WaitSnapshotReadyTimeout(t *testing.T) {
}
config["wait_snapshot_ready_timeout"] = ALICLOUD_DEFAULT_TIMEOUT
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}

View File

@ -182,7 +182,7 @@ type Builder struct {
runner multistep.Runner
}
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
b.config.ctx.Funcs = awscommon.TemplateFuncs
err := config.Decode(&b.config, &config.DecodeOpts{
Interpolate: true,
@ -201,7 +201,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
},
}, raws...)
if err != nil {
return nil, err
return nil, nil, err
}
if b.config.Architecture == "" {
@ -319,11 +319,11 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}
if errs != nil && len(errs.Errors) > 0 {
return warns, errs
return nil, warns, errs
}
packer.LogSecretFilter.Set(b.config.AccessKey, b.config.SecretKey, b.config.Token)
return warns, nil
return nil, warns, nil
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

View File

@ -31,7 +31,7 @@ func TestBuilderPrepare_AMIName(t *testing.T) {
// Test good
config["ami_name"] = "foo"
config["skip_region_validation"] = true
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -42,7 +42,7 @@ func TestBuilderPrepare_AMIName(t *testing.T) {
// Test bad
config["ami_name"] = "foo {{"
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -53,7 +53,7 @@ func TestBuilderPrepare_AMIName(t *testing.T) {
// Test bad
delete(config, "ami_name")
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -67,7 +67,7 @@ func TestBuilderPrepare_ChrootMounts(t *testing.T) {
config := testConfig()
config["chroot_mounts"] = nil
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -83,7 +83,7 @@ func TestBuilderPrepare_ChrootMountsBadDefaults(t *testing.T) {
config["chroot_mounts"] = [][]string{
{"bad"},
}
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -96,7 +96,7 @@ func TestBuilderPrepare_SourceAmi(t *testing.T) {
config := testConfig()
config["source_ami"] = ""
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -105,7 +105,7 @@ func TestBuilderPrepare_SourceAmi(t *testing.T) {
}
config["source_ami"] = "foo"
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -119,7 +119,7 @@ func TestBuilderPrepare_CommandWrapper(t *testing.T) {
config := testConfig()
config["command_wrapper"] = "echo hi; {{.Command}}"
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -132,7 +132,7 @@ func TestBuilderPrepare_CopyFiles(t *testing.T) {
b := &Builder{}
config := testConfig()
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -150,7 +150,7 @@ func TestBuilderPrepare_CopyFilesNoDefault(t *testing.T) {
config := testConfig()
config["copy_files"] = []string{}
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -171,7 +171,7 @@ func TestBuilderPrepare_RootDeviceNameAndAMIMappings(t *testing.T) {
config["root_device_name"] = "/dev/sda"
config["ami_block_device_mappings"] = []interface{}{map[string]string{}}
config["root_volume_size"] = 15
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) == 0 {
t.Fatal("Missing warning, stating block device mappings will be overwritten")
} else if len(warnings) > 1 {
@ -187,7 +187,7 @@ func TestBuilderPrepare_AMIMappingsNoRootDeviceName(t *testing.T) {
config := testConfig()
config["ami_block_device_mappings"] = []interface{}{map[string]string{}}
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -201,7 +201,7 @@ func TestBuilderPrepare_RootDeviceNameNoAMIMappings(t *testing.T) {
config := testConfig()
config["root_device_name"] = "/dev/sda"
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}

View File

@ -72,7 +72,7 @@ type Builder struct {
runner multistep.Runner
}
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
b.config.ctx.Funcs = awscommon.TemplateFuncs
err := config.Decode(&b.config, &config.DecodeOpts{
Interpolate: true,
@ -89,7 +89,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
},
}, raws...)
if err != nil {
return nil, err
return nil, nil, err
}
if b.config.PackerConfig.PackerForce {
@ -123,11 +123,11 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}
if errs != nil && len(errs.Errors) > 0 {
return warns, errs
return nil, warns, errs
}
packer.LogSecretFilter.Set(b.config.AccessKey, b.config.SecretKey, b.config.Token)
return warns, nil
return nil, warns, nil
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

View File

@ -32,7 +32,7 @@ func TestBuilder_Prepare_BadType(t *testing.T) {
"access_key": []string{},
}
warnings, err := b.Prepare(c)
_, warnings, err := b.Prepare(c)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -48,7 +48,7 @@ func TestBuilderPrepare_AMIName(t *testing.T) {
// Test good
config["ami_name"] = "foo"
config["skip_region_validation"] = true
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -59,7 +59,7 @@ func TestBuilderPrepare_AMIName(t *testing.T) {
// Test bad
config["ami_name"] = "foo {{"
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -70,7 +70,7 @@ func TestBuilderPrepare_AMIName(t *testing.T) {
// Test bad
delete(config, "ami_name")
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -85,7 +85,7 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) {
// Add a random key
config["i_should_not_be_valid"] = true
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -101,7 +101,7 @@ func TestBuilderPrepare_InvalidShutdownBehavior(t *testing.T) {
// Test good
config["shutdown_behavior"] = "terminate"
config["skip_region_validation"] = true
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -111,7 +111,7 @@ func TestBuilderPrepare_InvalidShutdownBehavior(t *testing.T) {
// Test good
config["shutdown_behavior"] = "stop"
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -121,7 +121,7 @@ func TestBuilderPrepare_InvalidShutdownBehavior(t *testing.T) {
// Test bad
config["shutdown_behavior"] = "foobar"
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}

View File

@ -70,7 +70,7 @@ type Builder struct {
runner multistep.Runner
}
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
b.config.ctx.Funcs = awscommon.TemplateFuncs
err := config.Decode(&b.config, &config.DecodeOpts{
Interpolate: true,
@ -87,7 +87,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
},
}, raws...)
if err != nil {
return nil, err
return nil, nil, err
}
if b.config.PackerConfig.PackerForce {
@ -145,12 +145,12 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
errs = packer.MultiErrorAppend(errs, errors.New(`The only valid ami_architecture values are "x86_64" and "arm64"`))
}
if errs != nil && len(errs.Errors) > 0 {
return warns, errs
return nil, warns, errs
}
packer.LogSecretFilter.Set(b.config.AccessKey, b.config.SecretKey, b.config.Token)
return warns, nil
return nil, warns, nil
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

View File

@ -31,7 +31,7 @@ func TestBuilder_Prepare_BadType(t *testing.T) {
"access_key": []string{},
}
warnings, err := b.Prepare(c)
_, warnings, err := b.Prepare(c)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -46,7 +46,7 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) {
// Add a random key
config["i_should_not_be_valid"] = true
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}

View File

@ -79,7 +79,7 @@ type EngineVarsTemplate struct {
SourceAMI string
}
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
b.config.ctx.Funcs = awscommon.TemplateFuncs
// Create passthrough for {{ .BuildRegion }} and {{ .SourceAMI }} variables
// so we can fill them in later
@ -92,7 +92,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
InterpolateContext: &b.config.ctx,
}, raws...)
if err != nil {
return nil, err
return nil, nil, err
}
// Accumulate any errors
@ -129,11 +129,11 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}
if errs != nil && len(errs.Errors) > 0 {
return warns, errs
return nil, warns, errs
}
packer.LogSecretFilter.Set(b.config.AccessKey, b.config.SecretKey, b.config.Token)
return warns, nil
return nil, warns, nil
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

View File

@ -31,7 +31,7 @@ func TestBuilder_Prepare_BadType(t *testing.T) {
"access_key": []string{},
}
warnings, err := b.Prepare(c)
_, warnings, err := b.Prepare(c)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -46,7 +46,7 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) {
// Add a random key
config["i_should_not_be_valid"] = true
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -62,7 +62,7 @@ func TestBuilderPrepare_InvalidShutdownBehavior(t *testing.T) {
// Test good
config["shutdown_behavior"] = "terminate"
config["skip_region_validation"] = true
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -72,7 +72,7 @@ func TestBuilderPrepare_InvalidShutdownBehavior(t *testing.T) {
// Test good
config["shutdown_behavior"] = "stop"
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -82,7 +82,7 @@ func TestBuilderPrepare_InvalidShutdownBehavior(t *testing.T) {
// Test bad
config["shutdown_behavior"] = "foobar"
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}

View File

@ -93,7 +93,7 @@ type Builder struct {
runner multistep.Runner
}
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
configs := make([]interface{}, len(raws)+1)
configs[0] = map[string]interface{}{
"bundle_prefix": "image-{{timestamp}}",
@ -118,7 +118,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
},
}, configs...)
if err != nil {
return nil, err
return nil, nil, err
}
if b.config.PackerConfig.PackerForce {
@ -218,10 +218,10 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}
if errs != nil && len(errs.Errors) > 0 {
return warns, errs
return nil, warns, errs
}
packer.LogSecretFilter.Set(b.config.AccessKey, b.config.SecretKey, b.config.Token)
return warns, nil
return nil, warns, nil
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

View File

@ -47,7 +47,7 @@ func TestBuilderPrepare_AccountId(t *testing.T) {
defer tempfile.Close()
config["account_id"] = ""
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -56,7 +56,7 @@ func TestBuilderPrepare_AccountId(t *testing.T) {
}
config["account_id"] = "foo"
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -65,7 +65,7 @@ func TestBuilderPrepare_AccountId(t *testing.T) {
}
config["account_id"] = "0123-0456-7890"
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -87,7 +87,7 @@ func TestBuilderPrepare_AMIName(t *testing.T) {
// Test good
config["ami_name"] = "foo"
config["skip_region_validation"] = true
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -98,7 +98,7 @@ func TestBuilderPrepare_AMIName(t *testing.T) {
// Test bad
config["ami_name"] = "foo {{"
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -109,7 +109,7 @@ func TestBuilderPrepare_AMIName(t *testing.T) {
// Test bad
delete(config, "ami_name")
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -126,7 +126,7 @@ func TestBuilderPrepare_BundleDestination(t *testing.T) {
defer tempfile.Close()
config["bundle_destination"] = ""
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -146,7 +146,7 @@ func TestBuilderPrepare_BundlePrefix(t *testing.T) {
defer os.Remove(tempfile.Name())
defer tempfile.Close()
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -167,7 +167,7 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) {
// Add a random key
config["i_should_not_be_valid"] = true
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -184,7 +184,7 @@ func TestBuilderPrepare_S3Bucket(t *testing.T) {
defer tempfile.Close()
config["s3_bucket"] = ""
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -193,7 +193,7 @@ func TestBuilderPrepare_S3Bucket(t *testing.T) {
}
config["s3_bucket"] = "foo"
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -210,7 +210,7 @@ func TestBuilderPrepare_X509CertPath(t *testing.T) {
defer tempfile.Close()
config["x509_cert_path"] = ""
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -219,7 +219,7 @@ func TestBuilderPrepare_X509CertPath(t *testing.T) {
}
config["x509_cert_path"] = "i/am/a/file/that/doesnt/exist"
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -235,7 +235,7 @@ func TestBuilderPrepare_X509CertPath(t *testing.T) {
defer tf.Close()
config["x509_cert_path"] = tf.Name()
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -252,7 +252,7 @@ func TestBuilderPrepare_X509KeyPath(t *testing.T) {
defer tempfile.Close()
config["x509_key_path"] = ""
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -261,7 +261,7 @@ func TestBuilderPrepare_X509KeyPath(t *testing.T) {
}
config["x509_key_path"] = "i/am/a/file/that/doesnt/exist"
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -277,7 +277,7 @@ func TestBuilderPrepare_X509KeyPath(t *testing.T) {
defer tf.Close()
config["x509_key_path"] = tf.Name()
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -294,7 +294,7 @@ func TestBuilderPrepare_X509UploadPath(t *testing.T) {
defer tempfile.Close()
config["x509_upload_path"] = ""
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}

View File

@ -34,10 +34,10 @@ const (
DefaultSecretName = "packerKeyVaultSecret"
)
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
c, warnings, errs := newConfig(raws...)
if errs != nil {
return warnings, errs
return nil, warnings, errs
}
b.config = c
@ -47,7 +47,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
b.setTemplateParameters(b.stateBag)
b.setImageParameters(b.stateBag)
return warnings, errs
return nil, warnings, errs
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

View File

@ -8,7 +8,7 @@ import (
func TestStateBagShouldBePopulatedExpectedValues(t *testing.T) {
var testSubject = &Builder{}
_, err := testSubject.Prepare(getArmBuilderConfiguration(), getPackerConfiguration())
_, _, err := testSubject.Prepare(getArmBuilderConfiguration(), getPackerConfiguration())
if err != nil {
t.Fatalf("failed to prepare: %s", err)
}

View File

@ -116,7 +116,7 @@ type Builder struct {
runner multistep.Runner
}
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
b.config.ctx.Funcs = azcommon.TemplateFuncs
b.config.ctx.Funcs["vm"] = CreateVMMetadataTemplateFunc()
err := config.Decode(&b.config, &config.DecodeOpts{
@ -134,7 +134,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
},
}, raws...)
if err != nil {
return nil, err
return nil, nil, err
}
var errs *packer.MultiError
@ -143,7 +143,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
// Defaults
err = b.config.ClientConfig.SetDefaultValues()
if err != nil {
return nil, err
return nil, nil, err
}
if b.config.ChrootMounts == nil {
@ -254,11 +254,11 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}
if errs != nil {
return warns, errs
return nil, warns, errs
}
packer.LogSecretFilter.Set(b.config.ClientConfig.ClientSecret, b.config.ClientConfig.ClientJWT)
return warns, nil
return nil, warns, nil
}
func checkDiskCacheType(s string) interface{} {

View File

@ -55,7 +55,7 @@ func TestBuilder_Prepare(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
b := &Builder{}
_, err := b.Prepare(tt.config)
_, _, err := b.Prepare(tt.config)
if (err != nil) != tt.wantErr {
t.Errorf("Builder.Prepare() error = %v, wantErr %v", err, tt.wantErr)

View File

@ -21,14 +21,14 @@ type Builder struct {
}
// Prepare implements the packer.Builder interface.
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
config, errs := NewConfig(raws...)
if errs != nil {
return nil, errs
return nil, nil, errs
}
b.config = config
return nil, nil
return nil, nil, nil
}
// Run implements the packer.Builder interface.

View File

@ -43,7 +43,7 @@ func TestBuilder_Prepare(t *testing.T) {
b := &Builder{}
for desc, tc := range cases {
_, errs := b.Prepare(tc.Config)
_, _, errs := b.Prepare(tc.Config)
if tc.Err {
if errs == nil {

View File

@ -25,14 +25,14 @@ type Builder struct {
runner multistep.Runner
}
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
c, warnings, errs := NewConfig(raws...)
if errs != nil {
return warnings, errs
return nil, warnings, errs
}
b.config = *c
return nil, nil
return nil, nil, nil
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

View File

@ -32,7 +32,7 @@ func TestBuilder_Prepare_BadType(t *testing.T) {
"api_key": []string{},
}
warnings, err := b.Prepare(c)
_, warnings, err := b.Prepare(c)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -47,7 +47,7 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) {
// Add a random key
config["i_should_not_be_valid"] = true
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -62,7 +62,7 @@ func TestBuilderPrepare_Region(t *testing.T) {
// Test default
delete(config, "region")
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -75,7 +75,7 @@ func TestBuilderPrepare_Region(t *testing.T) {
// Test set
config["region"] = expected
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -94,7 +94,7 @@ func TestBuilderPrepare_Size(t *testing.T) {
// Test default
delete(config, "size")
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -107,7 +107,7 @@ func TestBuilderPrepare_Size(t *testing.T) {
// Test set
config["size"] = expected
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -126,7 +126,7 @@ func TestBuilderPrepare_Image(t *testing.T) {
// Test default
delete(config, "image")
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -139,7 +139,7 @@ func TestBuilderPrepare_Image(t *testing.T) {
// Test set
config["image"] = expected
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -157,7 +157,7 @@ func TestBuilderPrepare_StateTimeout(t *testing.T) {
config := testConfig()
// Test default
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -172,7 +172,7 @@ func TestBuilderPrepare_StateTimeout(t *testing.T) {
// Test set
config["state_timeout"] = "5m"
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -183,7 +183,7 @@ func TestBuilderPrepare_StateTimeout(t *testing.T) {
// Test bad
config["state_timeout"] = "tubes"
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -197,7 +197,7 @@ func TestBuilderPrepare_SnapshotTimeout(t *testing.T) {
config := testConfig()
// Test default
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -212,7 +212,7 @@ func TestBuilderPrepare_SnapshotTimeout(t *testing.T) {
// Test set
config["snapshot_timeout"] = "15m"
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -223,7 +223,7 @@ func TestBuilderPrepare_SnapshotTimeout(t *testing.T) {
// Test bad
config["snapshot_timeout"] = "badstring"
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -237,7 +237,7 @@ func TestBuilderPrepare_PrivateNetworking(t *testing.T) {
config := testConfig()
// Test default
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -252,7 +252,7 @@ func TestBuilderPrepare_PrivateNetworking(t *testing.T) {
// Test set
config["private_networking"] = true
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -270,7 +270,7 @@ func TestBuilderPrepare_SnapshotName(t *testing.T) {
config := testConfig()
// Test default
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -285,7 +285,7 @@ func TestBuilderPrepare_SnapshotName(t *testing.T) {
// Test set
config["snapshot_name"] = "foobarbaz"
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -296,7 +296,7 @@ func TestBuilderPrepare_SnapshotName(t *testing.T) {
// Test set with template
config["snapshot_name"] = "{{timestamp}}"
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -316,7 +316,7 @@ func TestBuilderPrepare_DropletName(t *testing.T) {
config := testConfig()
// Test default
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -331,7 +331,7 @@ func TestBuilderPrepare_DropletName(t *testing.T) {
// Test normal set
config["droplet_name"] = "foobar"
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -342,7 +342,7 @@ func TestBuilderPrepare_DropletName(t *testing.T) {
// Test with template
config["droplet_name"] = "foobar-{{timestamp}}"
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -353,7 +353,7 @@ func TestBuilderPrepare_DropletName(t *testing.T) {
// Test with bad template
config["droplet_name"] = "foobar-{{"
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}

View File

@ -20,14 +20,14 @@ type Builder struct {
runner multistep.Runner
}
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
c, warnings, errs := NewConfig(raws...)
if errs != nil {
return warnings, errs
return nil, warnings, errs
}
b.config = c
return warnings, nil
return nil, warnings, nil
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

View File

@ -35,7 +35,7 @@ func TestUploadDownload(t *testing.T) {
// Setup the builder
builder := &Builder{}
warnings, err := builder.Prepare(tpl.Builders["docker"].Config)
_, warnings, err := builder.Prepare(tpl.Builders["docker"].Config)
if err != nil {
t.Fatalf("Error preparing configuration %s", err)
}
@ -118,7 +118,7 @@ func TestLargeDownload(t *testing.T) {
// Setup the builder
builder := &Builder{}
warnings, err := builder.Prepare(tpl.Builders["docker"].Config)
_, warnings, err := builder.Prepare(tpl.Builders["docker"].Config)
if err != nil {
t.Fatalf("Error preparing configuration %s", err)
}
@ -222,7 +222,7 @@ func TestFixUploadOwner(t *testing.T) {
// Setup the builder
builder := &Builder{}
warnings, err := builder.Prepare(tpl.Builders["docker"].Config)
_, warnings, err := builder.Prepare(tpl.Builders["docker"].Config)
if err != nil {
t.Fatalf("Error preparing configuration %s", err)
}

View File

@ -23,14 +23,14 @@ type Builder struct {
runner multistep.Runner
}
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
c, warnings, errs := NewConfig(raws...)
if errs != nil {
return warnings, errs
return nil, warnings, errs
}
b.config = c
return warnings, nil
return nil, warnings, nil
}
// Run is where the actual build should take place. It takes a Build and a Ui.

View File

@ -23,13 +23,13 @@ type Builder struct {
}
// Prepare processes the build configuration parameters.
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
c, warnings, errs := NewConfig(raws...)
if errs != nil {
return warnings, errs
return nil, warnings, errs
}
b.config = c
return warnings, nil
return nil, warnings, nil
}
// Run executes a googlecompute Packer build and returns a packer.Artifact

View File

@ -22,13 +22,13 @@ type Builder struct {
var pluginVersion = "1.0.0"
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
config, warnings, errs := NewConfig(raws...)
if errs != nil {
return warnings, errs
return nil, warnings, errs
}
b.config = *config
return nil, nil
return nil, nil, nil
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

View File

@ -20,10 +20,10 @@ type Builder struct {
client *openapi.APIClient
}
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
config, warnings, errs := NewConfig(raws...)
if errs != nil {
return warnings, errs
return nil, warnings, errs
}
b.config = *config
@ -43,7 +43,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
b.client = openapi.NewAPIClient(cfg)
return nil, nil
return nil, nil, nil
}
type wrappedCommandTemplate struct {

View File

@ -85,7 +85,7 @@ type Config struct {
}
// Prepare processes the build configuration parameters.
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
err := config.Decode(&b.config, &config.DecodeOpts{
Interpolate: true,
InterpolateContext: &b.config.ctx,
@ -96,7 +96,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
},
}, raws...)
if err != nil {
return nil, err
return nil, nil, err
}
// Accumulate any errors and warnings
@ -164,10 +164,10 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}
if errs != nil && len(errs.Errors) > 0 {
return warnings, errs
return nil, warnings, errs
}
return warnings, nil
return nil, warnings, nil
}
// Run executes a Packer build and returns a packer.Artifact representing

View File

@ -42,7 +42,7 @@ func TestBuilderPrepare_Defaults(t *testing.T) {
var b Builder
config := testConfig()
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -60,7 +60,7 @@ func TestBuilderPrepare_DiskSize(t *testing.T) {
config := testConfig()
delete(config, "disk_size")
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -74,7 +74,7 @@ func TestBuilderPrepare_DiskSize(t *testing.T) {
config["disk_size"] = 256
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -96,7 +96,7 @@ func TestBuilderPrepare_DiskBlockSize(t *testing.T) {
// Test default with empty disk_block_size
delete(config, "disk_block_size")
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -112,7 +112,7 @@ func TestBuilderPrepare_DiskBlockSize(t *testing.T) {
for _, test_size := range test_sizes {
config["disk_block_size"] = test_size
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if test_size > expected_max_block_size || test_size < expected_min_block_size {
if len(warns) > 0 {
t.Fatalf("bad, should have no warns: %#v", warns)
@ -153,7 +153,7 @@ func TestBuilderPrepare_FixedVHDFormat(t *testing.T) {
// use_fixed_vhd_format should work with generation = 1, skip_compaction
// = true, and differencing_disk = false
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -164,7 +164,7 @@ func TestBuilderPrepare_FixedVHDFormat(t *testing.T) {
//use_fixed_vhd_format should not work with differencing_disk = true
config["differencing_disk"] = true
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -176,7 +176,7 @@ func TestBuilderPrepare_FixedVHDFormat(t *testing.T) {
//use_fixed_vhd_format should not work with skip_compaction = false
config["skip_compaction"] = false
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -188,7 +188,7 @@ func TestBuilderPrepare_FixedVHDFormat(t *testing.T) {
//use_fixed_vhd_format should not work with generation = 2
config["generation"] = 2
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -202,7 +202,7 @@ func TestBuilderPrepare_FloppyFiles(t *testing.T) {
config := testConfig()
delete(config, "floppy_files")
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -217,7 +217,7 @@ func TestBuilderPrepare_FloppyFiles(t *testing.T) {
floppiesPath := "../../../common/test-fixtures/floppies"
config["floppy_files"] = []string{fmt.Sprintf("%s/bar.bat", floppiesPath), fmt.Sprintf("%s/foo.ps1", floppiesPath)}
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -236,7 +236,7 @@ func TestBuilderPrepare_InvalidFloppies(t *testing.T) {
config := testConfig()
config["floppy_files"] = []string{"nonexistent.bat", "nonexistent.ps1"}
b = Builder{}
_, errs := b.Prepare(config)
_, _, errs := b.Prepare(config)
if errs == nil {
t.Fatalf("Nonexistent floppies should trigger multierror")
}
@ -252,7 +252,7 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) {
// Add a random key
config["i_should_not_be_valid"] = true
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -267,7 +267,7 @@ func TestBuilderPrepare_ISOChecksum(t *testing.T) {
// Test bad
config["iso_checksum"] = ""
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -278,7 +278,7 @@ func TestBuilderPrepare_ISOChecksum(t *testing.T) {
// Test good
config["iso_checksum"] = "FOo"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -294,7 +294,7 @@ func TestBuilderPrepare_ISOChecksumType(t *testing.T) {
// Test bad
config["iso_checksum_type"] = ""
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -305,7 +305,7 @@ func TestBuilderPrepare_ISOChecksumType(t *testing.T) {
// Test good
config["iso_checksum_type"] = "mD5"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -320,7 +320,7 @@ func TestBuilderPrepare_ISOChecksumType(t *testing.T) {
// Test unknown
config["iso_checksum_type"] = "fake"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -331,7 +331,7 @@ func TestBuilderPrepare_ISOChecksumType(t *testing.T) {
// Test none
config["iso_checksum_type"] = "none"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) == 0 {
t.Fatalf("bad: %#v", warns)
}
@ -353,7 +353,7 @@ func TestBuilderPrepare_ISOUrl(t *testing.T) {
// Test both empty
config["iso_url"] = ""
b = Builder{}
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -364,7 +364,7 @@ func TestBuilderPrepare_ISOUrl(t *testing.T) {
// Test iso_url set
config["iso_url"] = "http://www.packer.io"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -381,7 +381,7 @@ func TestBuilderPrepare_ISOUrl(t *testing.T) {
config["iso_url"] = "http://www.packer.io"
config["iso_urls"] = []string{"http://www.packer.io"}
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -397,7 +397,7 @@ func TestBuilderPrepare_ISOUrl(t *testing.T) {
}
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -431,7 +431,7 @@ func TestBuilderPrepare_SizeNotRequiredWhenUsingExistingHarddrive(t *testing.T)
}
b = Builder{}
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -455,7 +455,7 @@ func TestBuilderPrepare_SizeNotRequiredWhenUsingExistingHarddrive(t *testing.T)
}
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -489,7 +489,7 @@ func TestBuilderPrepare_SizeIsRequiredWhenNotUsingExistingHarddrive(t *testing.T
}
b = Builder{}
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -517,7 +517,7 @@ func TestBuilderPrepare_MaximumOfSixtyFourAdditionalDisks(t *testing.T) {
config["disk_additional_size"] = disks
b = Builder{}
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -537,7 +537,7 @@ func TestBuilderPrepare_CommConfig(t *testing.T) {
config["winrm_host"] = "1.2.3.4"
var b Builder
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -565,7 +565,7 @@ func TestBuilderPrepare_CommConfig(t *testing.T) {
config["ssh_host"] = "1.2.3.4"
var b Builder
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -593,7 +593,7 @@ func TestUserVariablesInBootCommand(t *testing.T) {
config[packer.UserVariablesConfigKey] = map[string]string{"test-variable": "test"}
config["boot_command"] = []string{"blah {{user `test-variable`}} blah"}
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -634,7 +634,7 @@ func TestBuilderPrepare_UseLegacyNetworkAdapter(t *testing.T) {
config["use_legacy_network_adapter"] = true
b = Builder{}
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -646,7 +646,7 @@ func TestBuilderPrepare_UseLegacyNetworkAdapter(t *testing.T) {
config["generation"] = 2
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}

View File

@ -78,7 +78,7 @@ type Config struct {
}
// Prepare processes the build configuration parameters.
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
err := config.Decode(&b.config, &config.DecodeOpts{
Interpolate: true,
InterpolateContext: &b.config.ctx,
@ -89,7 +89,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
},
}, raws...)
if err != nil {
return nil, err
return nil, nil, err
}
// Accumulate any errors and warnings
@ -204,10 +204,10 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}
if errs != nil && len(errs.Errors) > 0 {
return warnings, errs
return nil, warnings, errs
}
return warnings, nil
return nil, warnings, nil
}
// Run executes a Packer build and returns a packer.Artifact representing

View File

@ -49,7 +49,7 @@ func TestBuilderPrepare_Defaults(t *testing.T) {
defer os.RemoveAll(td)
config["clone_from_vmcx_path"] = td
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -76,7 +76,7 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) {
// Add a random key
config["i_should_not_be_valid"] = true
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -90,7 +90,7 @@ func TestBuilderPrepare_CloneFromExistingMachineOrImportFromExportedMachineSetti
config := testConfig()
delete(config, "clone_from_vmcx_path")
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -114,7 +114,7 @@ func TestBuilderPrepare_ExportedMachinePathDoesNotExist(t *testing.T) {
config["clone_from_vmcx_path"] = td
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -138,7 +138,7 @@ func TestBuilderPrepare_ExportedMachinePathExists(t *testing.T) {
config["clone_from_vmcx_path"] = td
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -154,7 +154,7 @@ func disabled_TestBuilderPrepare_CloneFromVmSettingUsedSoNoCloneFromVmcxPathRequ
config["clone_from_vm_name"] = "test_machine_name_that_does_not_exist"
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -184,7 +184,7 @@ func TestBuilderPrepare_ISOChecksum(t *testing.T) {
// Test bad
config["iso_checksum"] = ""
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -195,7 +195,7 @@ func TestBuilderPrepare_ISOChecksum(t *testing.T) {
// Test good
config["iso_checksum"] = "FOo"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -219,7 +219,7 @@ func TestBuilderPrepare_ISOChecksumType(t *testing.T) {
// Test bad
config["iso_checksum_type"] = ""
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -230,7 +230,7 @@ func TestBuilderPrepare_ISOChecksumType(t *testing.T) {
// Test good
config["iso_checksum_type"] = "mD5"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -245,7 +245,7 @@ func TestBuilderPrepare_ISOChecksumType(t *testing.T) {
// Test none
config["iso_checksum_type"] = "none"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) == 0 {
t.Fatalf("bad: %#v", warns)
}
@ -276,7 +276,7 @@ func TestBuilderPrepare_ISOUrl(t *testing.T) {
// Test both empty (should be allowed, as we cloning a vm so we probably don't need an ISO file)
config["iso_url"] = ""
b = Builder{}
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -287,7 +287,7 @@ func TestBuilderPrepare_ISOUrl(t *testing.T) {
// Test iso_url set
config["iso_url"] = "http://www.packer.io"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -304,7 +304,7 @@ func TestBuilderPrepare_ISOUrl(t *testing.T) {
config["iso_url"] = "http://www.packer.io"
config["iso_urls"] = []string{"http://www.packer.io"}
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -320,7 +320,7 @@ func TestBuilderPrepare_ISOUrl(t *testing.T) {
}
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -350,7 +350,7 @@ func TestBuilderPrepare_FloppyFiles(t *testing.T) {
config["clone_from_vmcx_path"] = td
delete(config, "floppy_files")
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -365,7 +365,7 @@ func TestBuilderPrepare_FloppyFiles(t *testing.T) {
floppies_path := "../../../common/test-fixtures/floppies"
config["floppy_files"] = []string{fmt.Sprintf("%s/bar.bat", floppies_path), fmt.Sprintf("%s/foo.ps1", floppies_path)}
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -393,7 +393,7 @@ func TestBuilderPrepare_InvalidFloppies(t *testing.T) {
config["floppy_files"] = []string{"nonexistent.bat", "nonexistent.ps1"}
b = Builder{}
_, errs := b.Prepare(config)
_, _, errs := b.Prepare(config)
if errs == nil {
t.Fatalf("Nonexistent floppies should trigger multierror")
}
@ -422,7 +422,7 @@ func TestBuilderPrepare_CommConfig(t *testing.T) {
config["winrm_host"] = "1.2.3.4"
var b Builder
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -459,7 +459,7 @@ func TestBuilderPrepare_CommConfig(t *testing.T) {
config["ssh_host"] = "1.2.3.4"
var b Builder
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -494,7 +494,7 @@ func TestUserVariablesInBootCommand(t *testing.T) {
config[packer.UserVariablesConfigKey] = map[string]string{"test-variable": "test"}
config["boot_command"] = []string{"blah {{user `test-variable`}} blah"}
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}

View File

@ -11,7 +11,7 @@ import (
"github.com/hashicorp/packer/template/interpolate"
)
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
err := config.Decode(&b.config, &config.DecodeOpts{
Interpolate: true,
InterpolateContext: &b.config.ctx,
@ -22,19 +22,19 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
},
}, raws...)
if err != nil {
return nil, fmt.Errorf("[ERROR] Failed in decoding JSON->mapstructure")
return nil, nil, fmt.Errorf("[ERROR] Failed in decoding JSON->mapstructure")
}
errs := &packer.MultiError{}
errs = packer.MultiErrorAppend(errs, b.config.JDCloudCredentialConfig.Prepare(&b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.JDCloudInstanceSpecConfig.Prepare(&b.config.ctx)...)
if errs != nil && len(errs.Errors) != 0 {
return nil, errs
return nil, nil, errs
}
packer.LogSecretFilter.Set(b.config.AccessKey, b.config.SecretKey)
return nil, nil
return nil, nil, nil
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

View File

@ -25,13 +25,13 @@ type Builder struct {
runner multistep.Runner
}
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
c, warnings, errs := NewConfig(raws...)
if errs != nil {
return warnings, errs
return nil, warnings, errs
}
b.config = c
return nil, nil
return nil, nil, nil
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (ret packer.Artifact, err error) {

View File

@ -31,7 +31,7 @@ func TestBuilder_Prepare_BadType(t *testing.T) {
"linode_token": []string{},
}
warnings, err := b.Prepare(c)
_, warnings, err := b.Prepare(c)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -46,7 +46,7 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) {
// Add a random key
config["i_should_not_be_valid"] = true
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -61,7 +61,7 @@ func TestBuilderPrepare_Region(t *testing.T) {
// Test default
delete(config, "region")
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -74,7 +74,7 @@ func TestBuilderPrepare_Region(t *testing.T) {
// Test set
config["region"] = expected
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -93,7 +93,7 @@ func TestBuilderPrepare_Size(t *testing.T) {
// Test default
delete(config, "instance_type")
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -106,7 +106,7 @@ func TestBuilderPrepare_Size(t *testing.T) {
// Test set
config["instance_type"] = expected
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -125,7 +125,7 @@ func TestBuilderPrepare_Image(t *testing.T) {
// Test default
delete(config, "image")
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -138,7 +138,7 @@ func TestBuilderPrepare_Image(t *testing.T) {
// Test set
config["image"] = expected
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -156,7 +156,7 @@ func TestBuilderPrepare_ImageLabel(t *testing.T) {
config := testConfig()
// Test default
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -171,7 +171,7 @@ func TestBuilderPrepare_ImageLabel(t *testing.T) {
// Test set
config["image_label"] = "foobarbaz"
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -182,7 +182,7 @@ func TestBuilderPrepare_ImageLabel(t *testing.T) {
// Test set with template
config["image_label"] = "{{timestamp}}"
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -202,7 +202,7 @@ func TestBuilderPrepare_Label(t *testing.T) {
config := testConfig()
// Test default
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -217,7 +217,7 @@ func TestBuilderPrepare_Label(t *testing.T) {
// Test normal set
config["instance_label"] = "foobar"
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -228,7 +228,7 @@ func TestBuilderPrepare_Label(t *testing.T) {
// Test with template
config["instance_label"] = "foobar-{{timestamp}}"
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -239,7 +239,7 @@ func TestBuilderPrepare_Label(t *testing.T) {
// Test with bad template
config["instance_label"] = "foobar-{{"
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}

View File

@ -23,14 +23,14 @@ type Builder struct {
runner multistep.Runner
}
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
c, errs := NewConfig(raws...)
if errs != nil {
return nil, errs
return nil, nil, errs
}
b.config = c
return nil, nil
return nil, nil, nil
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

View File

@ -25,7 +25,7 @@ func TestBuilderPrepare_ConfigFile(t *testing.T) {
var b Builder
// Good
config := testConfig()
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -37,7 +37,7 @@ func TestBuilderPrepare_ConfigFile(t *testing.T) {
config = testConfig()
delete(config, "config_file")
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}

View File

@ -21,14 +21,14 @@ type Builder struct {
runner multistep.Runner
}
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
c, errs := NewConfig(raws...)
if errs != nil {
return nil, errs
return nil, nil, errs
}
b.config = c
return nil, nil
return nil, nil, nil
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

View File

@ -24,7 +24,7 @@ func TestBuilderPrepare_ConfigFile(t *testing.T) {
var b Builder
// Good
config := testConfig()
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -35,7 +35,7 @@ func TestBuilderPrepare_ConfigFile(t *testing.T) {
// Good, remote image
config = testConfig()
config["image"] = "remote:bar"
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -46,7 +46,7 @@ func TestBuilderPrepare_ConfigFile(t *testing.T) {
// Good, remote output image
config = testConfig()
config["output_image"] = "remote:foo"
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -58,7 +58,7 @@ func TestBuilderPrepare_ConfigFile(t *testing.T) {
config = testConfig()
delete(config, "image")
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}

View File

@ -17,16 +17,16 @@ type Builder struct {
runner multistep.Runner
}
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
c, warnings, errs := NewConfig(raws...)
if errs != nil {
return warnings, errs
return nil, warnings, errs
}
b.config = c
b.stateBag = new(multistep.BasicStateBag)
return warnings, nil
return nil, warnings, nil
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

View File

@ -16,14 +16,14 @@ type Builder struct {
runner multistep.Runner
}
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
c, warnings, errs := NewConfig(raws...)
if errs != nil {
return warnings, errs
return nil, warnings, errs
}
b.config = c
return warnings, nil
return nil, warnings, nil
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

View File

@ -18,14 +18,14 @@ type Builder struct {
runner multistep.Runner
}
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
c, warnings, errs := NewConfig(raws...)
if errs != nil {
return warnings, errs
return nil, warnings, errs
}
b.config = c
return warnings, nil
return nil, warnings, nil
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

View File

@ -30,7 +30,7 @@ func TestBuilder_Prepare_BadType(t *testing.T) {
"api_key": []string{},
}
warns, err := b.Prepare(c)
_, warns, err := b.Prepare(c)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -46,7 +46,7 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) {
config := testConfig()
config["i_should_not_be_valid"] = true
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}

View File

@ -35,13 +35,13 @@ type Builder struct {
runner multistep.Runner
}
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
err := config.Decode(&b.config, &config.DecodeOpts{
Interpolate: true,
InterpolateContext: &b.config.ctx,
}, raws...)
if err != nil {
return nil, err
return nil, nil, err
}
// Accumulate any errors
@ -51,11 +51,11 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare(&b.config.ctx)...)
if errs != nil && len(errs.Errors) > 0 {
return nil, errs
return nil, nil, errs
}
if b.config.ImageConfig.ImageDiskFormat != "" && !b.config.RunConfig.UseBlockStorageVolume {
return nil, fmt.Errorf("use_blockstorage_volume must be true if image_disk_format is specified.")
return nil, nil, fmt.Errorf("use_blockstorage_volume must be true if image_disk_format is specified.")
}
// By default, instance name is same as image name
@ -64,7 +64,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}
packer.LogSecretFilter.Set(b.config.Password)
return nil, nil
return nil, nil, nil
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

View File

@ -20,7 +20,7 @@ func TestBuilder_Prepare_BadType(t *testing.T) {
"password": []string{},
}
warns, err := b.Prepare(c)
_, warns, err := b.Prepare(c)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}

View File

@ -24,10 +24,10 @@ type Builder struct {
runner multistep.Runner
}
func (b *Builder) Prepare(rawConfig ...interface{}) ([]string, error) {
func (b *Builder) Prepare(rawConfig ...interface{}) ([]string, []string, error) {
config, err := NewConfig(rawConfig...)
if err != nil {
return nil, err
return nil, nil, err
}
b.config = config
@ -36,9 +36,9 @@ func (b *Builder) Prepare(rawConfig ...interface{}) ([]string, error) {
errs = packer.MultiErrorAppend(errs, b.config.PVConfig.Prepare(&b.config.ctx))
if errs != nil && len(errs.Errors) > 0 {
return nil, errs
return nil, nil, errs
}
return nil, nil
return nil, nil, nil
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

View File

@ -26,14 +26,14 @@ type Builder struct {
runner multistep.Runner
}
func (b *Builder) Prepare(rawConfig ...interface{}) ([]string, error) {
func (b *Builder) Prepare(rawConfig ...interface{}) ([]string, []string, error) {
config, err := NewConfig(rawConfig...)
if err != nil {
return nil, err
return nil, nil, err
}
b.config = config
return nil, nil
return nil, nil, nil
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

View File

@ -42,7 +42,7 @@ type Builder struct {
runner multistep.Runner
}
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
b.config.ctx.Funcs = osccommon.TemplateFuncs
err := config.Decode(&b.config, &config.DecodeOpts{
Interpolate: true,
@ -59,7 +59,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
},
}, raws...)
if err != nil {
return nil, err
return nil, nil, err
}
if b.config.PackerConfig.PackerForce {
@ -75,11 +75,11 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare(&b.config.ctx)...)
if errs != nil && len(errs.Errors) > 0 {
return nil, errs
return nil, nil, errs
}
packer.LogSecretFilter.Set(b.config.AccessKey, b.config.SecretKey, b.config.Token)
return nil, nil
return nil, nil, nil
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

View File

@ -32,7 +32,7 @@ func TestBuilder_Prepare_BadType(t *testing.T) {
"access_key": []string{},
}
warnings, err := b.Prepare(c)
_, warnings, err := b.Prepare(c)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -48,7 +48,7 @@ func TestBuilderPrepare_OMIName(t *testing.T) {
// Test good
config["omi_name"] = "foo"
config["skip_region_validation"] = true
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -59,7 +59,7 @@ func TestBuilderPrepare_OMIName(t *testing.T) {
// Test bad
config["omi_name"] = "foo {{"
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -70,7 +70,7 @@ func TestBuilderPrepare_OMIName(t *testing.T) {
// Test bad
delete(config, "omi_name")
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -85,7 +85,7 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) {
// Add a random key
config["i_should_not_be_valid"] = true
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -101,7 +101,7 @@ func TestBuilderPrepare_InvalidShutdownBehavior(t *testing.T) {
// Test good
config["shutdown_behavior"] = "terminate"
config["skip_region_validation"] = true
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -111,7 +111,7 @@ func TestBuilderPrepare_InvalidShutdownBehavior(t *testing.T) {
// Test good
config["shutdown_behavior"] = "stop"
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -121,7 +121,7 @@ func TestBuilderPrepare_InvalidShutdownBehavior(t *testing.T) {
// Test bad
config["shutdown_behavior"] = "foobar"
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}

View File

@ -39,7 +39,7 @@ type Builder struct {
runner multistep.Runner
}
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
b.config.ctx.Funcs = osccommon.TemplateFuncs
@ -58,7 +58,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
},
}, raws...)
if err != nil {
return nil, err
return nil, nil, err
}
if b.config.PackerConfig.PackerForce {
@ -90,11 +90,11 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}
if errs != nil && len(errs.Errors) > 0 {
return nil, errs
return nil, nil, errs
}
packer.LogSecretFilter.Set(b.config.AccessKey, b.config.SecretKey, b.config.Token)
return nil, nil
return nil, nil, nil
}

View File

@ -44,7 +44,7 @@ type EngineVarsTemplate struct {
SourceOMI string
}
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
b.config.ctx.Funcs = osccommon.TemplateFuncs
// Create passthrough for {{ .BuildRegion }} and {{ .SourceOMI }} variables
// so we can fill them in later
@ -57,7 +57,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
InterpolateContext: &b.config.ctx,
}, raws...)
if err != nil {
return nil, err
return nil, nil, err
}
// Accumulate any errors
@ -78,11 +78,11 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}
if errs != nil && len(errs.Errors) > 0 {
return nil, errs
return nil, nil, errs
}
packer.LogSecretFilter.Set(b.config.AccessKey, b.config.SecretKey, b.config.Token)
return nil, nil
return nil, nil, nil
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

View File

@ -31,7 +31,7 @@ func TestBuilder_Prepare_BadType(t *testing.T) {
"access_key": []string{},
}
warnings, err := b.Prepare(c)
_, warnings, err := b.Prepare(c)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -46,7 +46,7 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) {
// Add a random key
config["i_should_not_be_valid"] = true
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -62,7 +62,7 @@ func TestBuilderPrepare_InvalidShutdownBehavior(t *testing.T) {
// Test good
config["shutdown_behavior"] = "terminate"
config["skip_region_validation"] = true
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -72,7 +72,7 @@ func TestBuilderPrepare_InvalidShutdownBehavior(t *testing.T) {
// Test good
config["shutdown_behavior"] = "stop"
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -82,7 +82,7 @@ func TestBuilderPrepare_InvalidShutdownBehavior(t *testing.T) {
// Test bad
config["shutdown_behavior"] = "foobar"
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}

View File

@ -63,7 +63,7 @@ type Builder struct {
runner multistep.Runner
}
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
b.config.ctx.Funcs = osccommon.TemplateFuncs
err := config.Decode(&b.config, &config.DecodeOpts{
Interpolate: true,
@ -82,7 +82,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
},
}, raws...)
if err != nil {
return nil, err
return nil, nil, err
}
if b.config.PackerConfig.PackerForce {
@ -178,11 +178,11 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}
if errs != nil && len(errs.Errors) > 0 {
return warns, errs
return nil, warns, errs
}
packer.LogSecretFilter.Set(b.config.AccessKey, b.config.SecretKey, b.config.Token)
return warns, nil
return nil, warns, nil
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

View File

@ -82,7 +82,7 @@ type Config struct {
ctx interpolate.Context
}
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
err := config.Decode(&b.config, &config.DecodeOpts{
Interpolate: true,
InterpolateContext: &b.config.ctx,
@ -96,7 +96,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
},
}, raws...)
if err != nil {
return nil, err
return nil, nil, err
}
// Accumulate any errors and warnings
@ -169,10 +169,10 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}
if errs != nil && len(errs.Errors) > 0 {
return warnings, errs
return nil, warnings, errs
}
return warnings, nil
return nil, warnings, nil
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

View File

@ -32,7 +32,7 @@ func TestBuilder_ImplementsBuilder(t *testing.T) {
func TestBuilderPrepare_Defaults(t *testing.T) {
var b Builder
config := testConfig()
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -54,7 +54,7 @@ func TestBuilderPrepare_FloppyFiles(t *testing.T) {
config := testConfig()
delete(config, "floppy_files")
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -69,7 +69,7 @@ func TestBuilderPrepare_FloppyFiles(t *testing.T) {
floppies_path := "../../../common/test-fixtures/floppies"
config["floppy_files"] = []string{fmt.Sprintf("%s/bar.bat", floppies_path), fmt.Sprintf("%s/foo.ps1", floppies_path)}
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -88,7 +88,7 @@ func TestBuilderPrepare_InvalidFloppies(t *testing.T) {
config := testConfig()
config["floppy_files"] = []string{"nonexistent.bat", "nonexistent.ps1"}
b = Builder{}
_, errs := b.Prepare(config)
_, _, errs := b.Prepare(config)
if errs == nil {
t.Fatalf("Nonexistent floppies should trigger multierror")
}
@ -103,7 +103,7 @@ func TestBuilderPrepare_DiskSize(t *testing.T) {
config := testConfig()
delete(config, "disk_size")
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -117,7 +117,7 @@ func TestBuilderPrepare_DiskSize(t *testing.T) {
config["disk_size"] = 60000
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -136,7 +136,7 @@ func TestBuilderPrepare_DiskType(t *testing.T) {
// Test a default disk_type
delete(config, "disk_type")
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -151,7 +151,7 @@ func TestBuilderPrepare_DiskType(t *testing.T) {
// Test with a bad
config["disk_type"] = "fake"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -163,7 +163,7 @@ func TestBuilderPrepare_DiskType(t *testing.T) {
config["disk_type"] = "plain"
config["skip_compaction"] = false
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) == 0 {
t.Fatalf("should have warning")
}
@ -175,7 +175,7 @@ func TestBuilderPrepare_DiskType(t *testing.T) {
config["disk_type"] = "plain"
config["skip_compaction"] = true
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -191,7 +191,7 @@ func TestBuilderPrepare_HardDriveInterface(t *testing.T) {
// Test a default boot_wait
delete(config, "hard_drive_interface")
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -206,7 +206,7 @@ func TestBuilderPrepare_HardDriveInterface(t *testing.T) {
// Test with a bad
config["hard_drive_interface"] = "fake"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -217,7 +217,7 @@ func TestBuilderPrepare_HardDriveInterface(t *testing.T) {
// Test with a good
config["hard_drive_interface"] = "scsi"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -232,7 +232,7 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) {
// Add a random key
config["i_should_not_be_valid"] = true
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}

View File

@ -20,14 +20,14 @@ type Builder struct {
}
// Prepare processes the build configuration parameters.
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
c, warnings, errs := NewConfig(raws...)
if errs != nil {
return warnings, errs
return nil, warnings, errs
}
b.config = c
return warnings, nil
return nil, warnings, nil
}
// Run executes a Packer build and returns a packer.Artifact representing

View File

@ -17,14 +17,14 @@ type Builder struct {
runner multistep.Runner
}
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
c, warnings, errs := NewConfig(raws...)
if errs != nil {
return warnings, errs
return nil, warnings, errs
}
b.config = c
return warnings, nil
return nil, warnings, nil
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

View File

@ -31,7 +31,7 @@ func TestBuilder_Prepare_BadType(t *testing.T) {
"api_key": []string{},
}
warns, err := b.Prepare(c)
_, warns, err := b.Prepare(c)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -47,7 +47,7 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) {
config := testConfig()
config["i_should_not_be_valid"] = true
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}

View File

@ -27,13 +27,13 @@ var _ packer.Builder = &Builder{}
var pluginVersion = "1.0.0"
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
config, warnings, errs := NewConfig(raws...)
if errs != nil {
return warnings, errs
return nil, warnings, errs
}
b.config = *config
return nil, nil
return nil, nil, nil
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

View File

@ -81,7 +81,7 @@ func TestBasicExampleFromDocsIsValid(t *testing.T) {
}
b := &Builder{}
warn, err := b.Prepare(tpl.Builders["proxmox"].Config)
_, warn, err := b.Prepare(tpl.Builders["proxmox"].Config)
if err != nil {
t.Fatal(err, warn)
}
@ -149,7 +149,7 @@ func TestAgentSetToFalse(t *testing.T) {
}
b := &Builder{}
warn, err := b.Prepare(tpl.Builders["proxmox"].Config)
_, warn, err := b.Prepare(tpl.Builders["proxmox"].Config)
if err != nil {
t.Fatal(err, warn)
}

View File

@ -336,7 +336,7 @@ type Config struct {
ctx interpolate.Context
}
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
err := config.Decode(&b.config, &config.DecodeOpts{
Interpolate: true,
InterpolateContext: &b.config.ctx,
@ -348,7 +348,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
},
}, raws...)
if err != nil {
return nil, err
return nil, nil, err
}
var errs *packer.MultiError
@ -569,10 +569,10 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}
if errs != nil && len(errs.Errors) > 0 {
return warnings, errs
return nil, warnings, errs
}
return warnings, nil
return nil, warnings, nil
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

View File

@ -62,7 +62,7 @@ func TestBuilder_ImplementsBuilder(t *testing.T) {
func TestBuilderPrepare_Defaults(t *testing.T) {
var b Builder
config := testConfig()
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -101,7 +101,7 @@ func TestBuilderPrepare_VNCBindAddress(t *testing.T) {
// Test a default boot_wait
delete(config, "vnc_bind_address")
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -122,7 +122,7 @@ func TestBuilderPrepare_DiskCompaction(t *testing.T) {
config["skip_compaction"] = false
config["disk_compression"] = true
config["format"] = "img"
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -141,7 +141,7 @@ func TestBuilderPrepare_DiskCompaction(t *testing.T) {
config["disk_compression"] = true
config["format"] = "qcow2"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -178,7 +178,7 @@ func TestBuilderPrepare_DiskSize(t *testing.T) {
delete(config, "disk_size")
config["disk_size"] = tc.InputSize
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -198,7 +198,7 @@ func TestBuilderPrepare_AdditionalDiskSize(t *testing.T) {
config["disk_additional_size"] = []string{"1M"}
config["disk_image"] = true
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -209,7 +209,7 @@ func TestBuilderPrepare_AdditionalDiskSize(t *testing.T) {
delete(config, "disk_image")
config["disk_additional_size"] = []string{"1M"}
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -228,7 +228,7 @@ func TestBuilderPrepare_Format(t *testing.T) {
// Bad
config["format"] = "illegal value"
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -239,7 +239,7 @@ func TestBuilderPrepare_Format(t *testing.T) {
// Good
config["format"] = "qcow2"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -250,7 +250,7 @@ func TestBuilderPrepare_Format(t *testing.T) {
// Good
config["format"] = "raw"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -269,7 +269,7 @@ func TestBuilderPrepare_UseBackingFile(t *testing.T) {
config["disk_image"] = false
config["format"] = "qcow2"
b = Builder{}
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -281,7 +281,7 @@ func TestBuilderPrepare_UseBackingFile(t *testing.T) {
config["disk_image"] = true
config["format"] = "raw"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -293,7 +293,7 @@ func TestBuilderPrepare_UseBackingFile(t *testing.T) {
config["disk_image"] = true
config["format"] = "qcow2"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -307,7 +307,7 @@ func TestBuilderPrepare_FloppyFiles(t *testing.T) {
config := testConfig()
delete(config, "floppy_files")
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -322,7 +322,7 @@ func TestBuilderPrepare_FloppyFiles(t *testing.T) {
floppies_path := "../../common/test-fixtures/floppies"
config["floppy_files"] = []string{fmt.Sprintf("%s/bar.bat", floppies_path), fmt.Sprintf("%s/foo.ps1", floppies_path)}
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -341,7 +341,7 @@ func TestBuilderPrepare_InvalidFloppies(t *testing.T) {
config := testConfig()
config["floppy_files"] = []string{"nonexistent.bat", "nonexistent.ps1"}
b = Builder{}
_, errs := b.Prepare(config)
_, _, errs := b.Prepare(config)
if errs == nil {
t.Fatalf("Nonexistent floppies should trigger multierror")
}
@ -357,7 +357,7 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) {
// Add a random key
config["i_should_not_be_valid"] = true
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -379,7 +379,7 @@ func TestBuilderPrepare_OutputDir(t *testing.T) {
config["output_directory"] = dir
b = Builder{}
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -390,7 +390,7 @@ func TestBuilderPrepare_OutputDir(t *testing.T) {
// Test with a good one
config["output_directory"] = "i-hope-i-dont-exist"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -405,7 +405,7 @@ func TestBuilderPrepare_ShutdownTimeout(t *testing.T) {
// Test with a bad value
config["shutdown_timeout"] = "this is not good"
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -416,7 +416,7 @@ func TestBuilderPrepare_ShutdownTimeout(t *testing.T) {
// Test with a good one
config["shutdown_timeout"] = "5s"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -433,7 +433,7 @@ func TestBuilderPrepare_SSHHostPort(t *testing.T) {
config["ssh_host_port_min"] = 1000
config["ssh_host_port_max"] = 500
b = Builder{}
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -444,7 +444,7 @@ func TestBuilderPrepare_SSHHostPort(t *testing.T) {
// Bad
config["ssh_host_port_min"] = -500
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -456,7 +456,7 @@ func TestBuilderPrepare_SSHHostPort(t *testing.T) {
config["ssh_host_port_min"] = 500
config["ssh_host_port_max"] = 1000
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -471,7 +471,7 @@ func TestBuilderPrepare_SSHPrivateKey(t *testing.T) {
config["ssh_private_key_file"] = ""
b = Builder{}
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -481,7 +481,7 @@ func TestBuilderPrepare_SSHPrivateKey(t *testing.T) {
config["ssh_private_key_file"] = "/i/dont/exist"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -503,7 +503,7 @@ func TestBuilderPrepare_SSHPrivateKey(t *testing.T) {
config["ssh_private_key_file"] = tf.Name()
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -517,7 +517,7 @@ func TestBuilderPrepare_SSHPrivateKey(t *testing.T) {
tf.Write([]byte(testPem))
config["ssh_private_key_file"] = tf.Name()
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -532,7 +532,7 @@ func TestBuilderPrepare_SSHWaitTimeout(t *testing.T) {
// Test a default boot_wait
delete(config, "ssh_wait_timeout")
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -543,7 +543,7 @@ func TestBuilderPrepare_SSHWaitTimeout(t *testing.T) {
// Test with a bad value
config["ssh_wait_timeout"] = "this is not good"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -554,7 +554,7 @@ func TestBuilderPrepare_SSHWaitTimeout(t *testing.T) {
// Test with a good one
config["ssh_wait_timeout"] = "5s"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -569,7 +569,7 @@ func TestBuilderPrepare_QemuArgs(t *testing.T) {
// Test with empty
delete(config, "qemuargs")
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -587,7 +587,7 @@ func TestBuilderPrepare_QemuArgs(t *testing.T) {
}
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -611,7 +611,7 @@ func TestBuilderPrepare_VNCPassword(t *testing.T) {
config["vnc_use_password"] = true
config["output_directory"] = "not-a-real-directory"
b = Builder{}
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}

View File

@ -23,14 +23,14 @@ type Builder struct {
runner multistep.Runner
}
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
c, warnings, errs := NewConfig(raws...)
if errs != nil {
return warnings, errs
return nil, warnings, errs
}
b.config = c
return nil, nil
return nil, nil, nil
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

View File

@ -32,7 +32,7 @@ func TestBuilder_Prepare_BadType(t *testing.T) {
"api_token": []string{},
}
warnings, err := b.Prepare(c)
_, warnings, err := b.Prepare(c)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -46,7 +46,7 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) {
config := testConfig()
config["i_should_not_be_valid"] = true
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -60,7 +60,7 @@ func TestBuilderPrepare_Region(t *testing.T) {
config := testConfig()
delete(config, "region")
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -72,7 +72,7 @@ func TestBuilderPrepare_Region(t *testing.T) {
config["region"] = expected
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -90,7 +90,7 @@ func TestBuilderPrepare_CommercialType(t *testing.T) {
config := testConfig()
delete(config, "commercial_type")
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -102,7 +102,7 @@ func TestBuilderPrepare_CommercialType(t *testing.T) {
config["commercial_type"] = expected
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -120,7 +120,7 @@ func TestBuilderPrepare_Image(t *testing.T) {
config := testConfig()
delete(config, "image")
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -132,7 +132,7 @@ func TestBuilderPrepare_Image(t *testing.T) {
config["image"] = expected
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -149,7 +149,7 @@ func TestBuilderPrepare_SnapshotName(t *testing.T) {
var b Builder
config := testConfig()
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -163,7 +163,7 @@ func TestBuilderPrepare_SnapshotName(t *testing.T) {
config["snapshot_name"] = "foobarbaz"
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -173,7 +173,7 @@ func TestBuilderPrepare_SnapshotName(t *testing.T) {
config["snapshot_name"] = "{{timestamp}}"
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -192,7 +192,7 @@ func TestBuilderPrepare_ServerName(t *testing.T) {
var b Builder
config := testConfig()
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -206,7 +206,7 @@ func TestBuilderPrepare_ServerName(t *testing.T) {
config["server_name"] = "foobar"
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -216,7 +216,7 @@ func TestBuilderPrepare_ServerName(t *testing.T) {
config["server_name"] = "foobar-{{timestamp}}"
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -226,7 +226,7 @@ func TestBuilderPrepare_ServerName(t *testing.T) {
config["server_name"] = "foobar-{{"
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}

View File

@ -31,7 +31,7 @@ type Builder struct {
runner multistep.Runner
}
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
err := config.Decode(&b.config, &config.DecodeOpts{
Interpolate: true,
InterpolateContext: &b.config.ctx,
@ -43,7 +43,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}, raws...)
b.config.ctx.EnableEnv = true
if err != nil {
return nil, err
return nil, nil, err
}
// Accumulate any errors
@ -52,13 +52,13 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
errs = packer.MultiErrorAppend(errs, b.config.TencentCloudImageConfig.Prepare(&b.config.ctx)...)
errs = packer.MultiErrorAppend(errs, b.config.TencentCloudRunConfig.Prepare(&b.config.ctx)...)
if errs != nil && len(errs.Errors) > 0 {
return nil, errs
return nil, nil, errs
}
packer.LogSecretFilter.Set(b.config.SecretId, b.config.SecretKey)
log.Printf("[DEBUG]packer config: %v", b.config)
return nil, nil
return nil, nil, nil
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

View File

@ -20,7 +20,7 @@ type Builder struct {
runner multistep.Runner
}
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
errs := &multierror.Error{}
err := config.Decode(&b.config, &config.DecodeOpts{
@ -42,7 +42,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
b.config.Comm.SSHAgentAuth = true
}
return nil, errs.ErrorOrNil()
return nil, nil, errs.ErrorOrNil()
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

View File

@ -33,7 +33,7 @@ type Builder struct {
runner multistep.Runner
}
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
err := config.Decode(&b.config, &config.DecodeOpts{
Interpolate: true,
InterpolateContext: &b.config.ctx,
@ -45,7 +45,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}, raws...)
b.config.ctx.EnableEnv = true
if err != nil {
return nil, err
return nil, nil, err
}
// Accumulate any errors
@ -55,11 +55,11 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare(&b.config.ctx)...)
if errs != nil && len(errs.Errors) > 0 {
return nil, errs
return nil, nil, errs
}
packer.LogSecretFilter.Set(b.config.PublicKey, b.config.PrivateKey)
return nil, nil
return nil, nil, nil
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

View File

@ -35,7 +35,7 @@ func TestBuilder_Prepare_BadType(t *testing.T) {
"public_key": []string{},
}
warnings, err := b.Prepare(c)
_, warnings, err := b.Prepare(c)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -50,7 +50,7 @@ func TestBuilderPrepare_ImageName(t *testing.T) {
// Test good
config["image_name"] = "foo"
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -61,7 +61,7 @@ func TestBuilderPrepare_ImageName(t *testing.T) {
// Test bad
config["image_name"] = "foo {{"
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -72,7 +72,7 @@ func TestBuilderPrepare_ImageName(t *testing.T) {
// Test bad
delete(config, "image_name")
b = Builder{}
warnings, err = b.Prepare(config)
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -87,7 +87,7 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) {
// Add a random key
config["i_should_not_be_valid"] = true
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
@ -113,7 +113,7 @@ func TestBuilderPrepare_ImageDestinations(t *testing.T) {
"description": "bar",
},
}
warnings, err := b.Prepare(config)
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}

View File

@ -132,7 +132,7 @@ type Config struct {
}
// Prepare processes the build configuration parameters.
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
b.config = new(Config)
err := config.Decode(&b.config, &config.DecodeOpts{
Interpolate: true,
@ -144,7 +144,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
},
}, raws...)
if err != nil {
return nil, err
return nil, nil, err
}
// Accumulate any errors and warnings
@ -215,10 +215,10 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}
if errs != nil && len(errs.Errors) > 0 {
return warnings, errs
return nil, warnings, errs
}
return warnings, nil
return nil, warnings, nil
}
// Run executes a Packer build and returns a packer.Artifact representing

View File

@ -83,7 +83,7 @@ func TestBuilder_Prepare_ValidateSource(t *testing.T) {
}
for _, tc := range cases {
_, err := b.Prepare(tc.config)
_, _, err := b.Prepare(tc.config)
if (err != nil) != tc.errExpected {
t.Fatalf("Unexpected behavior from test case %#v; %s.", tc.config, tc.reason)
}

View File

@ -130,7 +130,7 @@ type Config struct {
ctx interpolate.Context
}
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
err := config.Decode(&b.config, &config.DecodeOpts{
Interpolate: true,
InterpolateContext: &b.config.ctx,
@ -145,7 +145,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
},
}, raws...)
if err != nil {
return nil, err
return nil, nil, err
}
// Accumulate any errors and warnings
@ -267,10 +267,10 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}
if errs != nil && len(errs.Errors) > 0 {
return warnings, errs
return nil, warnings, errs
}
return warnings, nil
return nil, warnings, nil
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

View File

@ -32,7 +32,7 @@ func TestBuilder_ImplementsBuilder(t *testing.T) {
func TestBuilderPrepare_Defaults(t *testing.T) {
var b Builder
config := testConfig()
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -62,7 +62,7 @@ func TestBuilderPrepare_DiskSize(t *testing.T) {
config := testConfig()
delete(config, "disk_size")
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -76,7 +76,7 @@ func TestBuilderPrepare_DiskSize(t *testing.T) {
config["disk_size"] = 60000
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -94,7 +94,7 @@ func TestBuilderPrepare_FloppyFiles(t *testing.T) {
config := testConfig()
delete(config, "floppy_files")
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -109,7 +109,7 @@ func TestBuilderPrepare_FloppyFiles(t *testing.T) {
floppies_path := "../../../common/test-fixtures/floppies"
config["floppy_files"] = []string{fmt.Sprintf("%s/bar.bat", floppies_path), fmt.Sprintf("%s/foo.ps1", floppies_path)}
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -128,7 +128,7 @@ func TestBuilderPrepare_InvalidFloppies(t *testing.T) {
config := testConfig()
config["floppy_files"] = []string{"nonexistent.bat", "nonexistent.ps1"}
b = Builder{}
_, errs := b.Prepare(config)
_, _, errs := b.Prepare(config)
if errs == nil {
t.Fatalf("Nonexistent floppies should trigger multierror")
}
@ -144,7 +144,7 @@ func TestBuilderPrepare_GuestAdditionsMode(t *testing.T) {
// test default mode
delete(config, "guest_additions_mode")
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -155,7 +155,7 @@ func TestBuilderPrepare_GuestAdditionsMode(t *testing.T) {
// Test another mode
config["guest_additions_mode"] = "attach"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -170,7 +170,7 @@ func TestBuilderPrepare_GuestAdditionsMode(t *testing.T) {
// Test bad mode
config["guest_additions_mode"] = "teleport"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -184,7 +184,7 @@ func TestBuilderPrepare_GuestAdditionsPath(t *testing.T) {
config := testConfig()
delete(config, "guest_additions_path")
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -198,7 +198,7 @@ func TestBuilderPrepare_GuestAdditionsPath(t *testing.T) {
config["guest_additions_path"] = "foo"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -216,7 +216,7 @@ func TestBuilderPrepare_GuestAdditionsSHA256(t *testing.T) {
config := testConfig()
delete(config, "guest_additions_sha256")
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -230,7 +230,7 @@ func TestBuilderPrepare_GuestAdditionsSHA256(t *testing.T) {
config["guest_additions_sha256"] = "FOO"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -248,7 +248,7 @@ func TestBuilderPrepare_GuestAdditionsURL(t *testing.T) {
config := testConfig()
config["guest_additions_url"] = ""
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -262,7 +262,7 @@ func TestBuilderPrepare_GuestAdditionsURL(t *testing.T) {
config["guest_additions_url"] = "http://www.packer.io"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -277,7 +277,7 @@ func TestBuilderPrepare_HardDriveInterface(t *testing.T) {
// Test a default boot_wait
delete(config, "hard_drive_interface")
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -292,7 +292,7 @@ func TestBuilderPrepare_HardDriveInterface(t *testing.T) {
// Test with a bad
config["hard_drive_interface"] = "fake"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -303,7 +303,7 @@ func TestBuilderPrepare_HardDriveInterface(t *testing.T) {
// Test with a good
config["hard_drive_interface"] = "sata"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -318,7 +318,7 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) {
// Add a random key
config["i_should_not_be_valid"] = true
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -333,7 +333,7 @@ func TestBuilderPrepare_ISOInterface(t *testing.T) {
// Test a default boot_wait
delete(config, "iso_interface")
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -348,7 +348,7 @@ func TestBuilderPrepare_ISOInterface(t *testing.T) {
// Test with a bad
config["iso_interface"] = "fake"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -359,7 +359,7 @@ func TestBuilderPrepare_ISOInterface(t *testing.T) {
// Test with a good
config["iso_interface"] = "sata"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}

View File

@ -20,14 +20,14 @@ type Builder struct {
}
// Prepare processes the build configuration parameters.
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
c, warnings, errs := NewConfig(raws...)
if errs != nil {
return warnings, errs
return nil, warnings, errs
}
b.config = c
return warnings, nil
return nil, warnings, nil
}
// Run executes a Packer build and returns a packer.Artifact representing

View File

@ -20,14 +20,14 @@ type Builder struct {
}
// Prepare processes the build configuration parameters.
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
c, warnings, errs := NewConfig(raws...)
if errs != nil {
return warnings, errs
return nil, warnings, errs
}
b.config = c
return warnings, nil
return nil, warnings, nil
}
// Run executes a Packer build and returns a packer.Artifact representing

View File

@ -19,15 +19,15 @@ type Builder struct {
}
// Prepare processes the build configuration parameters.
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
c, warnings, errs := NewConfig(raws...)
if errs != nil {
return warnings, errs
return nil, warnings, errs
}
b.config = *c
return warnings, nil
return nil, warnings, nil
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {

View File

@ -33,7 +33,7 @@ func TestBuilder_ImplementsBuilder(t *testing.T) {
func TestBuilderPrepare_Defaults(t *testing.T) {
var b Builder
config := testConfig()
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -63,7 +63,7 @@ func TestBuilderPrepare_DiskSize(t *testing.T) {
config := testConfig()
delete(config, "disk_size")
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -77,7 +77,7 @@ func TestBuilderPrepare_DiskSize(t *testing.T) {
config["disk_size"] = 60000
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -95,7 +95,7 @@ func TestBuilderPrepare_FloppyFiles(t *testing.T) {
config := testConfig()
delete(config, "floppy_files")
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -110,7 +110,7 @@ func TestBuilderPrepare_FloppyFiles(t *testing.T) {
floppies_path := "../../../common/test-fixtures/floppies"
config["floppy_files"] = []string{fmt.Sprintf("%s/bar.bat", floppies_path), fmt.Sprintf("%s/foo.ps1", floppies_path)}
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -129,7 +129,7 @@ func TestBuilderPrepare_InvalidFloppies(t *testing.T) {
config := testConfig()
config["floppy_files"] = []string{"nonexistent.bat", "nonexistent.ps1"}
b = Builder{}
_, errs := b.Prepare(config)
_, _, errs := b.Prepare(config)
if errs == nil {
t.Fatalf("Nonexistent floppies should trigger multierror")
}
@ -149,7 +149,7 @@ func TestBuilderPrepare_RemoteType(t *testing.T) {
config["skip_validate_credentials"] = true
// Bad
config["remote_type"] = "foobar"
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -161,7 +161,7 @@ func TestBuilderPrepare_RemoteType(t *testing.T) {
// Bad
config["remote_host"] = ""
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -176,7 +176,7 @@ func TestBuilderPrepare_RemoteType(t *testing.T) {
config["remote_password"] = ""
config["remote_private_key_file"] = ""
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -189,7 +189,7 @@ func TestBuilderPrepare_RemoteType(t *testing.T) {
config["remote_host"] = "foobar.example.com"
config["remote_password"] = "supersecret"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -207,7 +207,7 @@ func TestBuilderPrepare_RemoteExport(t *testing.T) {
config["skip_validate_credentials"] = true
// Bad
config["remote_password"] = ""
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) != 0 {
t.Fatalf("bad: %#v", warns)
}
@ -218,7 +218,7 @@ func TestBuilderPrepare_RemoteExport(t *testing.T) {
// Good
config["remote_password"] = "supersecret"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) != 0 {
t.Fatalf("err: %s", err)
}
@ -233,7 +233,7 @@ func TestBuilderPrepare_Format(t *testing.T) {
// Bad
config["format"] = "foobar"
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -252,7 +252,7 @@ func TestBuilderPrepare_Format(t *testing.T) {
config["skip_validate_credentials"] = true
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -268,7 +268,7 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) {
// Add a random key
config["i_should_not_be_valid"] = true
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -290,7 +290,7 @@ func TestBuilderPrepare_OutputDir(t *testing.T) {
config["output_directory"] = dir
b = Builder{}
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -301,7 +301,7 @@ func TestBuilderPrepare_OutputDir(t *testing.T) {
// Test with a good one
config["output_directory"] = "i-hope-i-dont-exist"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -316,7 +316,7 @@ func TestBuilderPrepare_ToolsUploadPath(t *testing.T) {
// Test a default
delete(config, "tools_upload_path")
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -331,7 +331,7 @@ func TestBuilderPrepare_ToolsUploadPath(t *testing.T) {
// Test with a bad value
config["tools_upload_path"] = "{{{nope}"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -342,7 +342,7 @@ func TestBuilderPrepare_ToolsUploadPath(t *testing.T) {
// Test with a good one
config["tools_upload_path"] = "hey"
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -357,7 +357,7 @@ func TestBuilderPrepare_VMXTemplatePath(t *testing.T) {
// Test bad
config["vmx_template_path"] = "/i/dont/exist/forreal"
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -379,7 +379,7 @@ func TestBuilderPrepare_VMXTemplatePath(t *testing.T) {
config["vmx_template_path"] = tf.Name()
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -401,7 +401,7 @@ func TestBuilderPrepare_VMXTemplatePath(t *testing.T) {
config["vmx_template_path"] = tf2.Name()
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -417,7 +417,7 @@ func TestBuilderPrepare_VNCPort(t *testing.T) {
// Bad
config["vnc_port_min"] = 1000
config["vnc_port_max"] = 500
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -428,7 +428,7 @@ func TestBuilderPrepare_VNCPort(t *testing.T) {
// Bad
config["vnc_port_min"] = -500
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -440,7 +440,7 @@ func TestBuilderPrepare_VNCPort(t *testing.T) {
config["vnc_port_min"] = 500
config["vnc_port_max"] = 1000
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -458,7 +458,7 @@ func TestBuilderCheckCollisions(t *testing.T) {
}
{
var b Builder
warns, _ := b.Prepare(config)
_, warns, _ := b.Prepare(config)
if len(warns) != 1 {
t.Fatalf("Should have warning about two collisions.")
}
@ -466,7 +466,7 @@ func TestBuilderCheckCollisions(t *testing.T) {
{
config["vmx_template_path"] = "some/path.vmx"
var b Builder
warns, _ := b.Prepare(config)
_, warns, _ := b.Prepare(config)
if len(warns) != 0 {
t.Fatalf("Should not check for collisions with custom template.")
}
@ -484,7 +484,7 @@ func TestBuilderPrepare_CommConfig(t *testing.T) {
config["winrm_host"] = "1.2.3.4"
var b Builder
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -512,7 +512,7 @@ func TestBuilderPrepare_CommConfig(t *testing.T) {
config["ssh_host"] = "1.2.3.4"
var b Builder
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}

View File

@ -22,14 +22,14 @@ type Builder struct {
}
// Prepare processes the build configuration parameters.
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
c, warnings, errs := NewConfig(raws...)
if errs != nil {
return warnings, errs
return nil, warnings, errs
}
b.config = c
return warnings, nil
return nil, warnings, nil
}
// Run executes a Packer build and returns a packer.Artifact representing

View File

@ -24,7 +24,7 @@ func TestBuilderPrepare_FloppyFiles(t *testing.T) {
config["source_path"] = tf.Name()
delete(config, "floppy_files")
warns, err := b.Prepare(config)
_, warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -39,7 +39,7 @@ func TestBuilderPrepare_FloppyFiles(t *testing.T) {
floppies_path := "../../../common/test-fixtures/floppies"
config["floppy_files"] = []string{fmt.Sprintf("%s/bar.bat", floppies_path), fmt.Sprintf("%s/foo.ps1", floppies_path)}
b = Builder{}
warns, err = b.Prepare(config)
_, warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
@ -58,7 +58,7 @@ func TestBuilderPrepare_InvalidFloppies(t *testing.T) {
config := testConfig(t)
config["floppy_files"] = []string{"nonexistent.bat", "nonexistent.ps1"}
b = Builder{}
_, errs := b.Prepare(config)
_, _, errs := b.Prepare(config)
if errs == nil {
t.Fatalf("Nonexistent floppies should trigger multierror")
}

View File

@ -24,13 +24,13 @@ type Builder struct {
}
// Prepare processes the build configuration parameters.
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
c, warnings, errs := NewConfig(raws...)
if errs != nil {
return warnings, errs
return nil, warnings, errs
}
b.config = c
return warnings, nil
return nil, warnings, nil
}
// Run executes a yandex Packer build and returns a packer.Artifact

View File

@ -28,7 +28,9 @@ type ParallelTestBuilder struct {
wg sync.WaitGroup
}
func (b *ParallelTestBuilder) Prepare(raws ...interface{}) ([]string, error) { return nil, nil }
func (b *ParallelTestBuilder) Prepare(raws ...interface{}) ([]string, []string, error) {
return nil, nil, nil
}
func (b *ParallelTestBuilder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
ui.Say("building")
@ -39,7 +41,7 @@ func (b *ParallelTestBuilder) Run(ctx context.Context, ui packer.Ui, hook packer
// LockedBuilder wont run until unlock is called
type LockedBuilder struct{ unlock chan interface{} }
func (b *LockedBuilder) Prepare(raws ...interface{}) ([]string, error) { return nil, nil }
func (b *LockedBuilder) Prepare(raws ...interface{}) ([]string, []string, error) { return nil, nil, nil }
func (b *LockedBuilder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
ui.Say("locking build")

View File

@ -5,6 +5,7 @@ package shell_local
import (
"errors"
"fmt"
// "log"
"os"
"path/filepath"
"runtime"
@ -49,10 +50,6 @@ type Config struct {
}
func Decode(config *Config, raws ...interface{}) error {
// Create passthrough for build-generated data so we can fill it in once we know
// it
config.ctx.Data = packer.BasicPlaceholderData()
err := configHelper.Decode(&config, &configHelper.DecodeOpts{
Interpolate: true,
InterpolateContext: &config.ctx,
@ -63,7 +60,8 @@ func Decode(config *Config, raws ...interface{}) error {
},
}, raws...)
if err != nil {
return fmt.Errorf("Error decoding config: %s, config is %#v, and raws is %#v", err, config, raws)
return fmt.Errorf("Error decoding config: %s", err)
// return fmt.Errorf("Error decoding config: %s, config is %#v, and raws is %#v", err, config, raws)
}
return nil

View File

@ -41,9 +41,11 @@ func Decode(target interface{}, config *DecodeOpts, raws ...interface{}) error {
config = &DecodeOpts{Interpolate: true}
}
// Detect user variables from the raws and merge them into our context
ctxData, raws := DetectContextData(raws...)
// Interpolate first
if config.Interpolate {
// Detect user variables from the raws and merge them into our context
ctx, err := DetectContext(raws...)
if err != nil {
return err
@ -55,6 +57,9 @@ func Decode(target interface{}, config *DecodeOpts, raws ...interface{}) error {
config.InterpolateContext.BuildType = ctx.BuildType
config.InterpolateContext.TemplatePath = ctx.TemplatePath
config.InterpolateContext.UserVariables = ctx.UserVariables
if config.InterpolateContext.Data == nil {
config.InterpolateContext.Data = ctxData
}
}
ctx = config.InterpolateContext
@ -103,7 +108,7 @@ func Decode(target interface{}, config *DecodeOpts, raws ...interface{}) error {
for _, unused := range md.Unused {
if unused != "type" && !strings.HasPrefix(unused, "packer_") {
err = multierror.Append(err, fmt.Errorf(
"unknown configuration key: %q", unused))
"unknown configuration key: %q; raws is %#v \n\n and ctx data is %#v", unused, raws, ctxData))
}
}
if err != nil {
@ -114,6 +119,39 @@ func Decode(target interface{}, config *DecodeOpts, raws ...interface{}) error {
return nil
}
func DetectContextData(raws ...interface{}) (map[interface{}]interface{}, []interface{}) {
// In provisioners, the last value pulled from raws is the placeholder data
// for build-specific variables. Pull these out to add to interpolation
// context.
// Internally, our tests may cause this to be read as a map[string]string
placeholderData := raws[len(raws)-1]
if pd, ok := placeholderData.(map[string]string); ok {
if uuid, ok := pd["PackerRunUUID"]; ok {
if strings.Contains(uuid, "Generated_PackerRunUUID.") {
cast := make(map[interface{}]interface{})
for k, v := range pd {
cast[k] = v
}
raws = raws[:len(raws)-1]
return cast, raws
}
}
}
// but with normal interface conversion across the rpc, it'll look like a
// map[interface]interface, not a map[string]string
if pd, ok := placeholderData.(map[interface{}]interface{}); ok {
if uuid, ok := pd["PackerRunUUID"]; ok {
if strings.Contains(uuid.(string), "Generated_PackerRunUUID.") {
raws = raws[:len(raws)-1]
return pd, raws
}
}
}
return nil, raws
}
// DetectContext builds a base interpolate.Context, automatically
// detecting things like user variables from the raw configuration params.
func DetectContext(raws ...interface{}) (*interpolate.Context, error) {

View File

@ -5,6 +5,8 @@ import (
"fmt"
"log"
"sync"
"github.com/hashicorp/packer/helper/common"
)
const (
@ -148,17 +150,30 @@ func (b *coreBuild) Prepare() (warn []string, err error) {
}
// Prepare the builder
warn, err = b.builder.Prepare(b.builderConfig, packerConfig)
generatedVars, warn, err := b.builder.Prepare(b.builderConfig, packerConfig)
if err != nil {
log.Printf("Build '%s' prepare failure: %s\n", b.name, err)
return
}
// If the builder has provided a list of to-be-generated variables that
// should be made accessible to provisioners, pass that list into
// the provisioner prepare() so that the provisioner can appropriately
// validate user input against what will become available.
generatedPlaceholderMap := BasicPlaceholderData()
if generatedVars != nil {
for _, k := range generatedVars {
generatedPlaceholderMap[k] = fmt.Sprintf("Generated_%s. "+
common.PlaceholderMsg, k)
}
}
// Prepare the provisioners
for _, coreProv := range b.provisioners {
configs := make([]interface{}, len(coreProv.config), len(coreProv.config)+1)
copy(configs, coreProv.config)
configs = append(configs, packerConfig)
configs = append(configs, generatedPlaceholderMap)
if err = coreProv.provisioner.Prepare(configs...); err != nil {
return
@ -170,6 +185,7 @@ func (b *coreBuild) Prepare() (warn []string, err error) {
configs := make([]interface{}, len(b.cleanupProvisioner.config), len(b.cleanupProvisioner.config)+1)
copy(configs, b.cleanupProvisioner.config)
configs = append(configs, packerConfig)
configs = append(configs, generatedPlaceholderMap)
err = b.cleanupProvisioner.provisioner.Prepare(configs...)
if err != nil {
return

View File

@ -69,7 +69,7 @@ func TestBuild_Prepare(t *testing.T) {
if !prov.PrepCalled {
t.Fatal("prep should be called")
}
if !reflect.DeepEqual(prov.PrepConfigs, []interface{}{42, packerConfig}) {
if !reflect.DeepEqual(prov.PrepConfigs, []interface{}{42, packerConfig, BasicPlaceholderData()}) {
t.Fatalf("bad: %#v", prov.PrepConfigs)
}
@ -144,7 +144,7 @@ func TestBuild_Prepare_Debug(t *testing.T) {
if !prov.PrepCalled {
t.Fatal("prepare should be called")
}
if !reflect.DeepEqual(prov.PrepConfigs, []interface{}{42, packerConfig}) {
if !reflect.DeepEqual(prov.PrepConfigs, []interface{}{42, packerConfig, BasicPlaceholderData()}) {
t.Fatalf("bad: %#v", prov.PrepConfigs)
}
}

View File

@ -25,9 +25,10 @@ type Builder interface {
// Each of the configuration values should merge into the final
// configuration.
//
// Prepare should return a list of warnings along with any errors
// that occurred while preparing.
Prepare(...interface{}) ([]string, error)
// Prepare should return a list of variables that will be made accessible to
// users during the provison methods, a list of warnings along with any
// errors that occurred while preparing.
Prepare(...interface{}) ([]string, []string, error)
// Run is where the actual build should take place. It takes a Build and a Ui.
Run(context.Context, Ui, Hook) (Artifact, error)

View File

@ -23,10 +23,10 @@ type MockBuilder struct {
RunFn func(ctx context.Context)
}
func (tb *MockBuilder) Prepare(config ...interface{}) ([]string, error) {
func (tb *MockBuilder) Prepare(config ...interface{}) ([]string, []string, error) {
tb.PrepareCalled = true
tb.PrepareConfig = config
return tb.PrepareWarnings, nil
return nil, tb.PrepareWarnings, nil
}
func (tb *MockBuilder) Run(ctx context.Context, ui Ui, h Hook) (Artifact, error) {

View File

@ -12,7 +12,7 @@ type cmdBuilder struct {
client *Client
}
func (b *cmdBuilder) Prepare(config ...interface{}) ([]string, error) {
func (b *cmdBuilder) Prepare(config ...interface{}) ([]string, []string, error) {
defer func() {
r := recover()
b.checkExit(r, nil)

View File

@ -64,7 +64,7 @@ func BasicPlaceholderData() map[string]string {
placeholderData["User"] = fmt.Sprintf(msg, "User")
placeholderData["Password"] = fmt.Sprintf(msg, "Password")
placeholderData["ConnType"] = fmt.Sprintf(msg, "Type")
placeholderData["PACKER_RUN_UUID"] = fmt.Sprintf(msg, "PACKER_RUN_UUID")
placeholderData["PackerRunUUID"] = fmt.Sprintf(msg, "PackerRunUUID")
placeholderData["SSHPublicKey"] = fmt.Sprintf(msg, "SSHPublicKey")
placeholderData["SSHPrivateKey"] = fmt.Sprintf(msg, "SSHPrivateKey")
@ -75,6 +75,28 @@ func BasicPlaceholderData() map[string]string {
return placeholderData
}
func CastDataToMap(data interface{}) map[string]interface{} {
// Provisioners expect a map[string]interface{} in their data field, but
// it gets converted into a map[interface]interface on the way over the
// RPC. Check that data can be cast into such a form, and cast it.
cast := make(map[string]interface{})
interMap, ok := data.(map[interface{}]interface{})
if !ok {
log.Printf("Unable to read map[string]interface out of data."+
"Using empty interface: %#v", data)
} else {
for key, val := range interMap {
keyString, ok := key.(string)
if ok {
cast[keyString] = val
} else {
log.Printf("Error casting generated data key to a string.")
}
}
}
return cast
}
// Runs the provisioners in order.
func (h *ProvisionHook) Run(ctx context.Context, name string, ui Ui, comm Communicator, data interface{}) error {
// Shortcut
@ -91,25 +113,7 @@ func (h *ProvisionHook) Run(ctx context.Context, name string, ui Ui, comm Commun
for _, p := range h.Provisioners {
ts := CheckpointReporter.AddSpan(p.TypeName, "provisioner", p.Config)
// Provisioners expect a map[string]interface{} in their data field, but
// it gets converted into a map[interface]interface on the way over the
// RPC. Check that data can be cast into such a form, and cast it.
cast := make(map[string]interface{})
interMap, ok := data.(map[interface{}]interface{})
if !ok {
log.Printf("Unable to read map[string]interface out of data." +
"Using empty interface.")
} else {
for key, val := range interMap {
keyString, ok := key.(string)
if ok {
cast[keyString] = val
} else {
log.Printf("Error casting generated data key to a string.")
}
}
}
cast := CastDataToMap(data)
err := p.Provisioner.Provision(ctx, ui, comm, cast)
ts.End(err)

View File

@ -30,22 +30,23 @@ type BuilderPrepareArgs struct {
}
type BuilderPrepareResponse struct {
Warnings []string
Error *BasicError
GeneratedVars []string
Warnings []string
Error *BasicError
}
func (b *builder) Prepare(config ...interface{}) ([]string, error) {
func (b *builder) Prepare(config ...interface{}) ([]string, []string, error) {
var resp BuilderPrepareResponse
cerr := b.client.Call("Builder.Prepare", &BuilderPrepareArgs{config}, &resp)
if cerr != nil {
return nil, cerr
return nil, nil, cerr
}
var err error = nil
if resp.Error != nil {
err = resp.Error
}
return resp.Warnings, err
return resp.GeneratedVars, resp.Warnings, err
}
func (b *builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
@ -87,10 +88,11 @@ func (b *builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
}
func (b *BuilderServer) Prepare(args *BuilderPrepareArgs, reply *BuilderPrepareResponse) error {
warnings, err := b.builder.Prepare(args.Configs...)
generated, warnings, err := b.builder.Prepare(args.Configs...)
*reply = BuilderPrepareResponse{
Warnings: warnings,
Error: NewBasicError(err),
GeneratedVars: generated,
Warnings: warnings,
Error: NewBasicError(err),
}
return nil
}

View File

@ -20,7 +20,7 @@ func TestBuilderPrepare(t *testing.T) {
// Test Prepare
config := 42
warnings, err := bClient.Prepare(config)
_, warnings, err := bClient.Prepare(config)
if err != nil {
t.Fatalf("bad: %s", err)
}
@ -50,7 +50,7 @@ func TestBuilderPrepare_Warnings(t *testing.T) {
b.PrepareWarnings = expected
// Test Prepare
warnings, err := bClient.Prepare(nil)
_, warnings, err := bClient.Prepare(nil)
if err != nil {
t.Fatalf("bad: %s", err)
}

View File

@ -57,7 +57,7 @@ func setup(t *testing.T) (packer.Ui, packer.Artifact, error) {
// Prepare the file builder
builder := file.Builder{}
warnings, err := builder.Prepare(tpl.Builders["file"].Config)
_, warnings, err := builder.Prepare(tpl.Builders["file"].Config)
if len(warnings) > 0 {
for _, warn := range warnings {
return nil, nil, fmt.Errorf("Configuration warning: %s", warn)

View File

@ -197,7 +197,7 @@ func setup(t *testing.T) (packer.Ui, packer.Artifact, error) {
// Prepare the file builder
builder := file.Builder{}
warnings, err := builder.Prepare(tpl.Builders["file"].Config)
_, warnings, err := builder.Prepare(tpl.Builders["file"].Config)
if len(warnings) > 0 {
for _, warn := range warnings {
return nil, nil, fmt.Errorf("Configuration warning: %s", warn)

View File

@ -343,7 +343,7 @@ func testProvisionerProvisionDockerWithPlaybookFiles(t *testing.T, templateStrin
// Setup the builder
builder := &docker.Builder{}
warnings, err := builder.Prepare(tpl.Builders["docker"].Config)
_, warnings, err := builder.Prepare(tpl.Builders["docker"].Config)
if err != nil {
t.Fatalf("Error preparing configuration %s", err)
}

View File

@ -80,9 +80,6 @@ type Provisioner struct {
func (p *Provisioner) Prepare(raws ...interface{}) error {
p.done = make(chan struct{})
// Create passthrough for build-generated data
p.config.ctx.Data = packer.BasicPlaceholderData()
err := config.Decode(&p.config, &config.DecodeOpts{
Interpolate: true,
InterpolateContext: &p.config.ctx,

View File

@ -166,21 +166,22 @@ func funcGenTemplateDir(ctx *Context) interface{} {
func funcGenGenerated(ctx *Context) interface{} {
return func(s string) (string, error) {
if data, ok := ctx.Data.(map[string]string); ok {
if data, ok := ctx.Data.(map[interface{}]interface{}); ok {
// PlaceholderData has been passed into generator, so if the given
// key already exists in data, then we know it's an "allowed" key
if heldPlace, ok := data[s]; ok {
// If we're in the first interpolation pass, the goal is to
// make sure that we pass the value through.
// TODO match against an actual string constant
if strings.Contains(heldPlace, common.PlaceholderMsg) {
return fmt.Sprintf("{{.%s}}", s), nil
} else {
return heldPlace, nil
if hp, ok := heldPlace.(string); ok {
// If we're in the first interpolation pass, the goal is to
// make sure that we pass the value through.
// TODO match against an actual string constant
if strings.Contains(hp, common.PlaceholderMsg) {
return fmt.Sprintf("{{.%s}}", s), nil
} else {
return hp, nil
}
}
} else {
return "", fmt.Errorf("loaded data, but couldnt find %s in it.", s)
}
return "", fmt.Errorf("loaded data, but couldnt find %s in it.", s)
}
return "", fmt.Errorf("Error validating computed variable: the given "+