diff --git a/packer/core.go b/packer/core.go index a372c7ee8..3969da9c9 100644 --- a/packer/core.go +++ b/packer/core.go @@ -144,8 +144,11 @@ func (c *Core) Build(n string) (Build, error) { // Get the configuration config := make([]interface{}, 1, 2) config[0] = rawP.Config - - // TODO override + if rawP.Override != nil { + if override, ok := rawP.Override[rawName]; ok { + config = append(config, override) + } + } // If we're pausing, we wrap the provisioner in a special pauser. if rawP.PauseBefore > 0 { diff --git a/packer/core_test.go b/packer/core_test.go index 712694766..8cec16bae 100644 --- a/packer/core_test.go +++ b/packer/core_test.go @@ -222,6 +222,53 @@ func TestCoreBuild_provSkipInclude(t *testing.T) { } } +func TestCoreBuild_provOverride(t *testing.T) { + config := TestCoreConfig(t) + testCoreTemplate(t, config, fixtureDir("build-prov-override.json")) + b := TestBuilder(t, config, "test") + p := TestProvisioner(t, config, "test") + core := TestCore(t, config) + + b.ArtifactId = "hello" + + build, err := core.Build("test") + if err != nil { + t.Fatalf("err: %s", err) + } + + if _, err := build.Prepare(); err != nil { + t.Fatalf("err: %s", err) + } + + artifact, err := build.Run(nil, nil) + if err != nil { + t.Fatalf("err: %s", err) + } + if len(artifact) != 1 { + t.Fatalf("bad: %#v", artifact) + } + + if artifact[0].Id() != b.ArtifactId { + t.Fatalf("bad: %s", artifact[0].Id()) + } + if !p.ProvCalled { + t.Fatal("provisioner not called") + } + + found := false + for _, raw := range p.PrepConfigs { + if m, ok := raw.(map[string]interface{}); ok { + if _, ok := m["foo"]; ok { + found = true + break + } + } + } + if !found { + t.Fatal("override not called") + } +} + func TestCoreBuild_postProcess(t *testing.T) { config := TestCoreConfig(t) testCoreTemplate(t, config, fixtureDir("build-pp.json")) diff --git a/packer/test-fixtures/build-prov-override.json b/packer/test-fixtures/build-prov-override.json new file mode 100644 index 000000000..eb3554792 --- /dev/null +++ b/packer/test-fixtures/build-prov-override.json @@ -0,0 +1,14 @@ +{ + "builders": [{ + "type": "test" + }], + + "provisioners": [{ + "type": "test", + "override": { + "test": { + "foo": "bar" + } + } + }] +}