From 0f6d1beccf6cffee75acef741329bb80831b69f6 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Mon, 16 Dec 2019 21:23:05 -0800 Subject: [PATCH] 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. --- builder/alicloud/ecs/builder.go | 8 +-- builder/alicloud/ecs/builder_test.go | 22 +++--- builder/amazon/chroot/builder.go | 8 +-- builder/amazon/chroot/builder_test.go | 26 +++---- builder/amazon/ebs/builder.go | 8 +-- builder/amazon/ebs/builder_test.go | 16 ++--- builder/amazon/ebssurrogate/builder.go | 8 +-- builder/amazon/ebssurrogate/builder_test.go | 4 +- builder/amazon/ebsvolume/builder.go | 8 +-- builder/amazon/ebsvolume/builder_test.go | 10 +-- builder/amazon/instance/builder.go | 8 +-- builder/amazon/instance/builder_test.go | 36 +++++----- builder/azure/arm/builder.go | 6 +- builder/azure/arm/builder_test.go | 2 +- builder/azure/chroot/builder.go | 10 +-- builder/azure/chroot/builder_test.go | 2 +- builder/cloudstack/builder.go | 6 +- builder/cloudstack/builder_test.go | 2 +- builder/digitalocean/builder.go | 6 +- builder/digitalocean/builder_test.go | 46 ++++++------- builder/docker/builder.go | 6 +- builder/docker/communicator_test.go | 6 +- builder/file/builder.go | 6 +- builder/googlecompute/builder.go | 6 +- builder/hcloud/builder.go | 6 +- builder/hyperone/builder.go | 6 +- builder/hyperv/iso/builder.go | 8 +-- builder/hyperv/iso/builder_test.go | 64 ++++++++--------- builder/hyperv/vmcx/builder.go | 8 +-- builder/hyperv/vmcx/builder_test.go | 42 ++++++------ builder/jdcloud/builder.go | 8 +-- builder/linode/builder.go | 6 +- builder/linode/builder_test.go | 30 ++++---- builder/lxc/builder.go | 6 +- builder/lxc/builder_test.go | 4 +- builder/lxd/builder.go | 6 +- builder/lxd/builder_test.go | 8 +-- builder/ncloud/builder.go | 6 +- builder/null/builder.go | 6 +- builder/oneandone/builder.go | 6 +- builder/oneandone/builder_test.go | 4 +- builder/openstack/builder.go | 10 +-- builder/openstack/builder_test.go | 2 +- builder/oracle/classic/builder.go | 8 +-- builder/oracle/oci/builder.go | 6 +- builder/osc/bsu/builder.go | 8 +-- builder/osc/bsu/builder_test.go | 16 ++--- builder/osc/bsusurrogate/builder.go | 8 +-- builder/osc/bsuvolume/builder.go | 8 +-- builder/osc/bsuvolume/builder_test.go | 10 +-- builder/osc/chroot/builder.go | 8 +-- builder/parallels/iso/builder.go | 8 +-- builder/parallels/iso/builder_test.go | 28 ++++---- builder/parallels/pvm/builder.go | 6 +- builder/profitbricks/builder.go | 6 +- builder/profitbricks/builder_test.go | 4 +- builder/proxmox/builder.go | 6 +- builder/proxmox/config_test.go | 4 +- builder/qemu/builder.go | 8 +-- builder/qemu/builder_test.go | 68 +++++++++---------- builder/scaleway/builder.go | 6 +- builder/scaleway/builder_test.go | 30 ++++---- builder/tencentcloud/cvm/builder.go | 8 +-- builder/triton/builder.go | 4 +- builder/ucloud/uhost/builder.go | 8 +-- builder/ucloud/uhost/builder_test.go | 12 ++-- builder/vagrant/builder.go | 8 +-- builder/vagrant/builder_test.go | 2 +- builder/virtualbox/iso/builder.go | 8 +-- builder/virtualbox/iso/builder_test.go | 44 ++++++------ builder/virtualbox/ovf/builder.go | 6 +- builder/virtualbox/vm/builder.go | 6 +- builder/vmware/iso/builder.go | 6 +- builder/vmware/iso/builder_test.go | 60 ++++++++-------- builder/vmware/vmx/builder.go | 6 +- builder/vmware/vmx/builder_test.go | 6 +- builder/yandex/builder.go | 6 +- command/build_parallel_test.go | 6 +- common/shell-local/config.go | 8 +-- helper/config/decode.go | 42 +++++++++++- packer/build.go | 18 ++++- packer/build_test.go | 4 +- packer/builder.go | 7 +- packer/builder_mock.go | 4 +- packer/plugin/builder.go | 2 +- packer/provisioner.go | 44 ++++++------ packer/rpc/builder.go | 18 ++--- packer/rpc/builder_test.go | 4 +- .../checksum/post-processor_test.go | 2 +- .../compress/post-processor_test.go | 2 +- provisioner/ansible-local/provisioner_test.go | 2 +- provisioner/ansible/provisioner.go | 3 - template/interpolate/funcs.go | 21 +++--- 93 files changed, 592 insertions(+), 533 deletions(-) diff --git a/builder/alicloud/ecs/builder.go b/builder/alicloud/ecs/builder.go index 5b593cee9..44eab7fbd 100644 --- a/builder/alicloud/ecs/builder.go +++ b/builder/alicloud/ecs/builder.go @@ -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) { diff --git a/builder/alicloud/ecs/builder_test.go b/builder/alicloud/ecs/builder_test.go index e67861f5d..9a691de77 100644 --- a/builder/alicloud/ecs/builder_test.go +++ b/builder/alicloud/ecs/builder_test.go @@ -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) } diff --git a/builder/amazon/chroot/builder.go b/builder/amazon/chroot/builder.go index f1cf7432a..2a0331265 100644 --- a/builder/amazon/chroot/builder.go +++ b/builder/amazon/chroot/builder.go @@ -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) { diff --git a/builder/amazon/chroot/builder_test.go b/builder/amazon/chroot/builder_test.go index e6999bff6..b181b878f 100644 --- a/builder/amazon/chroot/builder_test.go +++ b/builder/amazon/chroot/builder_test.go @@ -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) } diff --git a/builder/amazon/ebs/builder.go b/builder/amazon/ebs/builder.go index f8648e204..08d93119c 100644 --- a/builder/amazon/ebs/builder.go +++ b/builder/amazon/ebs/builder.go @@ -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) { diff --git a/builder/amazon/ebs/builder_test.go b/builder/amazon/ebs/builder_test.go index a8200b5a8..4ea816130 100644 --- a/builder/amazon/ebs/builder_test.go +++ b/builder/amazon/ebs/builder_test.go @@ -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) } diff --git a/builder/amazon/ebssurrogate/builder.go b/builder/amazon/ebssurrogate/builder.go index abf159fad..835d86cdc 100644 --- a/builder/amazon/ebssurrogate/builder.go +++ b/builder/amazon/ebssurrogate/builder.go @@ -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) { diff --git a/builder/amazon/ebssurrogate/builder_test.go b/builder/amazon/ebssurrogate/builder_test.go index 94fdacd6b..37490bc61 100644 --- a/builder/amazon/ebssurrogate/builder_test.go +++ b/builder/amazon/ebssurrogate/builder_test.go @@ -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) } diff --git a/builder/amazon/ebsvolume/builder.go b/builder/amazon/ebsvolume/builder.go index b3d05299d..fc9305983 100644 --- a/builder/amazon/ebsvolume/builder.go +++ b/builder/amazon/ebsvolume/builder.go @@ -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) { diff --git a/builder/amazon/ebsvolume/builder_test.go b/builder/amazon/ebsvolume/builder_test.go index 85c8ae833..0d8b27ac1 100644 --- a/builder/amazon/ebsvolume/builder_test.go +++ b/builder/amazon/ebsvolume/builder_test.go @@ -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) } diff --git a/builder/amazon/instance/builder.go b/builder/amazon/instance/builder.go index 92a761459..79a688ec4 100644 --- a/builder/amazon/instance/builder.go +++ b/builder/amazon/instance/builder.go @@ -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) { diff --git a/builder/amazon/instance/builder_test.go b/builder/amazon/instance/builder_test.go index 0c2a05145..21d4d4030 100644 --- a/builder/amazon/instance/builder_test.go +++ b/builder/amazon/instance/builder_test.go @@ -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) } diff --git a/builder/azure/arm/builder.go b/builder/azure/arm/builder.go index 0a087c6fd..f1e6259c9 100644 --- a/builder/azure/arm/builder.go +++ b/builder/azure/arm/builder.go @@ -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) { diff --git a/builder/azure/arm/builder_test.go b/builder/azure/arm/builder_test.go index a71f92874..e9b781259 100644 --- a/builder/azure/arm/builder_test.go +++ b/builder/azure/arm/builder_test.go @@ -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) } diff --git a/builder/azure/chroot/builder.go b/builder/azure/chroot/builder.go index 91ceca991..c5fbefc9d 100644 --- a/builder/azure/chroot/builder.go +++ b/builder/azure/chroot/builder.go @@ -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{} { diff --git a/builder/azure/chroot/builder_test.go b/builder/azure/chroot/builder_test.go index dd40f7737..f84dd9ccc 100644 --- a/builder/azure/chroot/builder_test.go +++ b/builder/azure/chroot/builder_test.go @@ -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) diff --git a/builder/cloudstack/builder.go b/builder/cloudstack/builder.go index dc1dace69..138943956 100644 --- a/builder/cloudstack/builder.go +++ b/builder/cloudstack/builder.go @@ -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. diff --git a/builder/cloudstack/builder_test.go b/builder/cloudstack/builder_test.go index 6d7ab1444..0b61dfd20 100644 --- a/builder/cloudstack/builder_test.go +++ b/builder/cloudstack/builder_test.go @@ -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 { diff --git a/builder/digitalocean/builder.go b/builder/digitalocean/builder.go index 661e2c2a4..baaeffce1 100644 --- a/builder/digitalocean/builder.go +++ b/builder/digitalocean/builder.go @@ -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) { diff --git a/builder/digitalocean/builder_test.go b/builder/digitalocean/builder_test.go index 70ec6fea9..5113495cf 100644 --- a/builder/digitalocean/builder_test.go +++ b/builder/digitalocean/builder_test.go @@ -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) } diff --git a/builder/docker/builder.go b/builder/docker/builder.go index 63cb8f55d..f8b2bbf96 100644 --- a/builder/docker/builder.go +++ b/builder/docker/builder.go @@ -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) { diff --git a/builder/docker/communicator_test.go b/builder/docker/communicator_test.go index b028d367a..afaa5e60f 100644 --- a/builder/docker/communicator_test.go +++ b/builder/docker/communicator_test.go @@ -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) } diff --git a/builder/file/builder.go b/builder/file/builder.go index 0defa6049..a318e87eb 100644 --- a/builder/file/builder.go +++ b/builder/file/builder.go @@ -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. diff --git a/builder/googlecompute/builder.go b/builder/googlecompute/builder.go index 2a30d39c5..803970972 100644 --- a/builder/googlecompute/builder.go +++ b/builder/googlecompute/builder.go @@ -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 diff --git a/builder/hcloud/builder.go b/builder/hcloud/builder.go index 92f9f474b..3514d74ba 100644 --- a/builder/hcloud/builder.go +++ b/builder/hcloud/builder.go @@ -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) { diff --git a/builder/hyperone/builder.go b/builder/hyperone/builder.go index d9e85e5f0..fcaf50490 100644 --- a/builder/hyperone/builder.go +++ b/builder/hyperone/builder.go @@ -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 { diff --git a/builder/hyperv/iso/builder.go b/builder/hyperv/iso/builder.go index 1b40fac84..bde46d478 100644 --- a/builder/hyperv/iso/builder.go +++ b/builder/hyperv/iso/builder.go @@ -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 diff --git a/builder/hyperv/iso/builder_test.go b/builder/hyperv/iso/builder_test.go index 640221de2..b3c4736f3 100644 --- a/builder/hyperv/iso/builder_test.go +++ b/builder/hyperv/iso/builder_test.go @@ -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) } diff --git a/builder/hyperv/vmcx/builder.go b/builder/hyperv/vmcx/builder.go index af93007e5..17baf0b75 100644 --- a/builder/hyperv/vmcx/builder.go +++ b/builder/hyperv/vmcx/builder.go @@ -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 diff --git a/builder/hyperv/vmcx/builder_test.go b/builder/hyperv/vmcx/builder_test.go index 9f268aab4..2fa7ba3cf 100644 --- a/builder/hyperv/vmcx/builder_test.go +++ b/builder/hyperv/vmcx/builder_test.go @@ -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) } diff --git a/builder/jdcloud/builder.go b/builder/jdcloud/builder.go index 4b3700f11..4f6a4c0ba 100644 --- a/builder/jdcloud/builder.go +++ b/builder/jdcloud/builder.go @@ -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) { diff --git a/builder/linode/builder.go b/builder/linode/builder.go index 3bc3dfb3f..ce6850f72 100644 --- a/builder/linode/builder.go +++ b/builder/linode/builder.go @@ -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) { diff --git a/builder/linode/builder_test.go b/builder/linode/builder_test.go index c80d1c76c..8176114a4 100644 --- a/builder/linode/builder_test.go +++ b/builder/linode/builder_test.go @@ -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) } diff --git a/builder/lxc/builder.go b/builder/lxc/builder.go index 5c8747c7e..f5dfd4cbb 100644 --- a/builder/lxc/builder.go +++ b/builder/lxc/builder.go @@ -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) { diff --git a/builder/lxc/builder_test.go b/builder/lxc/builder_test.go index 4eeb27594..20108202d 100644 --- a/builder/lxc/builder_test.go +++ b/builder/lxc/builder_test.go @@ -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) } diff --git a/builder/lxd/builder.go b/builder/lxd/builder.go index ce1656217..a4a1d4863 100644 --- a/builder/lxd/builder.go +++ b/builder/lxd/builder.go @@ -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) { diff --git a/builder/lxd/builder_test.go b/builder/lxd/builder_test.go index b2ea70e55..a2277932c 100644 --- a/builder/lxd/builder_test.go +++ b/builder/lxd/builder_test.go @@ -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) } diff --git a/builder/ncloud/builder.go b/builder/ncloud/builder.go index 36702c933..1205573fd 100644 --- a/builder/ncloud/builder.go +++ b/builder/ncloud/builder.go @@ -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) { diff --git a/builder/null/builder.go b/builder/null/builder.go index 5939cd024..5bba58bc2 100644 --- a/builder/null/builder.go +++ b/builder/null/builder.go @@ -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) { diff --git a/builder/oneandone/builder.go b/builder/oneandone/builder.go index 5ea7674bc..785d9fdbd 100644 --- a/builder/oneandone/builder.go +++ b/builder/oneandone/builder.go @@ -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) { diff --git a/builder/oneandone/builder_test.go b/builder/oneandone/builder_test.go index daa8536e3..46045bf9d 100644 --- a/builder/oneandone/builder_test.go +++ b/builder/oneandone/builder_test.go @@ -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) } diff --git a/builder/openstack/builder.go b/builder/openstack/builder.go index 8411f803d..d8a3ae66f 100644 --- a/builder/openstack/builder.go +++ b/builder/openstack/builder.go @@ -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) { diff --git a/builder/openstack/builder_test.go b/builder/openstack/builder_test.go index 5fa296d30..0a9ac3288 100644 --- a/builder/openstack/builder_test.go +++ b/builder/openstack/builder_test.go @@ -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) } diff --git a/builder/oracle/classic/builder.go b/builder/oracle/classic/builder.go index d97b3be10..0905e4e84 100644 --- a/builder/oracle/classic/builder.go +++ b/builder/oracle/classic/builder.go @@ -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) { diff --git a/builder/oracle/oci/builder.go b/builder/oracle/oci/builder.go index a4b31b8e6..e54c4000b 100644 --- a/builder/oracle/oci/builder.go +++ b/builder/oracle/oci/builder.go @@ -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) { diff --git a/builder/osc/bsu/builder.go b/builder/osc/bsu/builder.go index ab4280417..e96011190 100644 --- a/builder/osc/bsu/builder.go +++ b/builder/osc/bsu/builder.go @@ -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) { diff --git a/builder/osc/bsu/builder_test.go b/builder/osc/bsu/builder_test.go index 1736044df..c700ccc06 100644 --- a/builder/osc/bsu/builder_test.go +++ b/builder/osc/bsu/builder_test.go @@ -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) } diff --git a/builder/osc/bsusurrogate/builder.go b/builder/osc/bsusurrogate/builder.go index 1186a5bdc..ed8b7cdf2 100644 --- a/builder/osc/bsusurrogate/builder.go +++ b/builder/osc/bsusurrogate/builder.go @@ -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 } diff --git a/builder/osc/bsuvolume/builder.go b/builder/osc/bsuvolume/builder.go index e0b5a8fa7..7ab76aa88 100644 --- a/builder/osc/bsuvolume/builder.go +++ b/builder/osc/bsuvolume/builder.go @@ -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) { diff --git a/builder/osc/bsuvolume/builder_test.go b/builder/osc/bsuvolume/builder_test.go index 956fba60f..27c4a80c0 100644 --- a/builder/osc/bsuvolume/builder_test.go +++ b/builder/osc/bsuvolume/builder_test.go @@ -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) } diff --git a/builder/osc/chroot/builder.go b/builder/osc/chroot/builder.go index e6813d263..ac506aa24 100644 --- a/builder/osc/chroot/builder.go +++ b/builder/osc/chroot/builder.go @@ -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) { diff --git a/builder/parallels/iso/builder.go b/builder/parallels/iso/builder.go index b7ea4788f..8764ad36a 100644 --- a/builder/parallels/iso/builder.go +++ b/builder/parallels/iso/builder.go @@ -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) { diff --git a/builder/parallels/iso/builder_test.go b/builder/parallels/iso/builder_test.go index 88a28144e..e131bc137 100644 --- a/builder/parallels/iso/builder_test.go +++ b/builder/parallels/iso/builder_test.go @@ -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) } diff --git a/builder/parallels/pvm/builder.go b/builder/parallels/pvm/builder.go index a199650d1..10296f4cc 100644 --- a/builder/parallels/pvm/builder.go +++ b/builder/parallels/pvm/builder.go @@ -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 diff --git a/builder/profitbricks/builder.go b/builder/profitbricks/builder.go index 3ab9d18fe..01bfeb1f5 100644 --- a/builder/profitbricks/builder.go +++ b/builder/profitbricks/builder.go @@ -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) { diff --git a/builder/profitbricks/builder_test.go b/builder/profitbricks/builder_test.go index 98252b410..f16953a33 100644 --- a/builder/profitbricks/builder_test.go +++ b/builder/profitbricks/builder_test.go @@ -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) } diff --git a/builder/proxmox/builder.go b/builder/proxmox/builder.go index 083cfeb3d..59038f6c2 100644 --- a/builder/proxmox/builder.go +++ b/builder/proxmox/builder.go @@ -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) { diff --git a/builder/proxmox/config_test.go b/builder/proxmox/config_test.go index 84dd13c6d..6733eda17 100644 --- a/builder/proxmox/config_test.go +++ b/builder/proxmox/config_test.go @@ -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) } diff --git a/builder/qemu/builder.go b/builder/qemu/builder.go index 6d85d2654..a8093f2fe 100644 --- a/builder/qemu/builder.go +++ b/builder/qemu/builder.go @@ -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) { diff --git a/builder/qemu/builder_test.go b/builder/qemu/builder_test.go index 4616ed3e2..4eea7174e 100644 --- a/builder/qemu/builder_test.go +++ b/builder/qemu/builder_test.go @@ -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) } diff --git a/builder/scaleway/builder.go b/builder/scaleway/builder.go index 47ddc8376..b1086955a 100644 --- a/builder/scaleway/builder.go +++ b/builder/scaleway/builder.go @@ -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) { diff --git a/builder/scaleway/builder_test.go b/builder/scaleway/builder_test.go index a1a0fccc3..cfb192614 100644 --- a/builder/scaleway/builder_test.go +++ b/builder/scaleway/builder_test.go @@ -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) } diff --git a/builder/tencentcloud/cvm/builder.go b/builder/tencentcloud/cvm/builder.go index 8934d0649..596f52534 100644 --- a/builder/tencentcloud/cvm/builder.go +++ b/builder/tencentcloud/cvm/builder.go @@ -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) { diff --git a/builder/triton/builder.go b/builder/triton/builder.go index ba6e2baa8..7a4cd54f1 100644 --- a/builder/triton/builder.go +++ b/builder/triton/builder.go @@ -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) { diff --git a/builder/ucloud/uhost/builder.go b/builder/ucloud/uhost/builder.go index a9903bf4a..6b2e25d4e 100644 --- a/builder/ucloud/uhost/builder.go +++ b/builder/ucloud/uhost/builder.go @@ -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) { diff --git a/builder/ucloud/uhost/builder_test.go b/builder/ucloud/uhost/builder_test.go index dca944bc5..70da65fa5 100644 --- a/builder/ucloud/uhost/builder_test.go +++ b/builder/ucloud/uhost/builder_test.go @@ -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) } diff --git a/builder/vagrant/builder.go b/builder/vagrant/builder.go index 5fb189e13..d6cd83d0a 100644 --- a/builder/vagrant/builder.go +++ b/builder/vagrant/builder.go @@ -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 diff --git a/builder/vagrant/builder_test.go b/builder/vagrant/builder_test.go index 65c2e5e9f..ee15b86e3 100644 --- a/builder/vagrant/builder_test.go +++ b/builder/vagrant/builder_test.go @@ -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) } diff --git a/builder/virtualbox/iso/builder.go b/builder/virtualbox/iso/builder.go index 02c7aeeac..ecdf1f470 100644 --- a/builder/virtualbox/iso/builder.go +++ b/builder/virtualbox/iso/builder.go @@ -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) { diff --git a/builder/virtualbox/iso/builder_test.go b/builder/virtualbox/iso/builder_test.go index 370ebe675..7f996efdf 100644 --- a/builder/virtualbox/iso/builder_test.go +++ b/builder/virtualbox/iso/builder_test.go @@ -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) } diff --git a/builder/virtualbox/ovf/builder.go b/builder/virtualbox/ovf/builder.go index b20b5b663..da63b6951 100644 --- a/builder/virtualbox/ovf/builder.go +++ b/builder/virtualbox/ovf/builder.go @@ -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 diff --git a/builder/virtualbox/vm/builder.go b/builder/virtualbox/vm/builder.go index 2336e58d5..ba76bacf1 100644 --- a/builder/virtualbox/vm/builder.go +++ b/builder/virtualbox/vm/builder.go @@ -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 diff --git a/builder/vmware/iso/builder.go b/builder/vmware/iso/builder.go index 7e94d9663..9de2d9284 100644 --- a/builder/vmware/iso/builder.go +++ b/builder/vmware/iso/builder.go @@ -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) { diff --git a/builder/vmware/iso/builder_test.go b/builder/vmware/iso/builder_test.go index 195f8e381..38441d633 100644 --- a/builder/vmware/iso/builder_test.go +++ b/builder/vmware/iso/builder_test.go @@ -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) } diff --git a/builder/vmware/vmx/builder.go b/builder/vmware/vmx/builder.go index e1e33dd7c..f33f14ffa 100644 --- a/builder/vmware/vmx/builder.go +++ b/builder/vmware/vmx/builder.go @@ -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 diff --git a/builder/vmware/vmx/builder_test.go b/builder/vmware/vmx/builder_test.go index 841d4f718..4e2a165a7 100644 --- a/builder/vmware/vmx/builder_test.go +++ b/builder/vmware/vmx/builder_test.go @@ -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") } diff --git a/builder/yandex/builder.go b/builder/yandex/builder.go index 69bb9469f..e59ae9b25 100644 --- a/builder/yandex/builder.go +++ b/builder/yandex/builder.go @@ -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 diff --git a/command/build_parallel_test.go b/command/build_parallel_test.go index a2dc240ae..a6228be32 100644 --- a/command/build_parallel_test.go +++ b/command/build_parallel_test.go @@ -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") diff --git a/common/shell-local/config.go b/common/shell-local/config.go index 46f2f8088..500cf0132 100644 --- a/common/shell-local/config.go +++ b/common/shell-local/config.go @@ -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 diff --git a/helper/config/decode.go b/helper/config/decode.go index 43673e1dc..5aefadcb4 100644 --- a/helper/config/decode.go +++ b/helper/config/decode.go @@ -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) { diff --git a/packer/build.go b/packer/build.go index badd67c1f..9c83c8992 100644 --- a/packer/build.go +++ b/packer/build.go @@ -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 diff --git a/packer/build_test.go b/packer/build_test.go index 0c58b405d..8102c4e67 100644 --- a/packer/build_test.go +++ b/packer/build_test.go @@ -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) } } diff --git a/packer/builder.go b/packer/builder.go index e24073128..349f94ba8 100644 --- a/packer/builder.go +++ b/packer/builder.go @@ -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) diff --git a/packer/builder_mock.go b/packer/builder_mock.go index 5ebd2d993..47dc5aec0 100644 --- a/packer/builder_mock.go +++ b/packer/builder_mock.go @@ -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) { diff --git a/packer/plugin/builder.go b/packer/plugin/builder.go index 44af7dd67..35665dc7b 100644 --- a/packer/plugin/builder.go +++ b/packer/plugin/builder.go @@ -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) diff --git a/packer/provisioner.go b/packer/provisioner.go index d20e4d360..b7f729bc3 100644 --- a/packer/provisioner.go +++ b/packer/provisioner.go @@ -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) diff --git a/packer/rpc/builder.go b/packer/rpc/builder.go index 4b95bea3e..5be4cc2bb 100644 --- a/packer/rpc/builder.go +++ b/packer/rpc/builder.go @@ -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 } diff --git a/packer/rpc/builder_test.go b/packer/rpc/builder_test.go index 9d89239b0..75d442865 100644 --- a/packer/rpc/builder_test.go +++ b/packer/rpc/builder_test.go @@ -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) } diff --git a/post-processor/checksum/post-processor_test.go b/post-processor/checksum/post-processor_test.go index fce5fd1cf..e52974ec4 100644 --- a/post-processor/checksum/post-processor_test.go +++ b/post-processor/checksum/post-processor_test.go @@ -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) diff --git a/post-processor/compress/post-processor_test.go b/post-processor/compress/post-processor_test.go index 0f5e1a19e..5b4cfcd9f 100644 --- a/post-processor/compress/post-processor_test.go +++ b/post-processor/compress/post-processor_test.go @@ -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) diff --git a/provisioner/ansible-local/provisioner_test.go b/provisioner/ansible-local/provisioner_test.go index 180bd0dc9..1b8e5e34a 100644 --- a/provisioner/ansible-local/provisioner_test.go +++ b/provisioner/ansible-local/provisioner_test.go @@ -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) } diff --git a/provisioner/ansible/provisioner.go b/provisioner/ansible/provisioner.go index 201bfd086..4ae101f6a 100644 --- a/provisioner/ansible/provisioner.go +++ b/provisioner/ansible/provisioner.go @@ -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, diff --git a/template/interpolate/funcs.go b/template/interpolate/funcs.go index b47ceb2dd..dfbaa9b50 100644 --- a/template/interpolate/funcs.go +++ b/template/interpolate/funcs.go @@ -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 "+