From dee1bc6c6796ceff547e69bd074421c57299817f Mon Sep 17 00:00:00 2001 From: Julian Phillips Date: Fri, 19 Jul 2013 15:35:05 +0100 Subject: [PATCH 1/2] packer/template: Test that builder.rawConfig excludes name The name isn't actually part of the builder config, so it should be removed during parsing. --- packer/template_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packer/template_test.go b/packer/template_test.go index af7e3e402..32d38222f 100644 --- a/packer/template_test.go +++ b/packer/template_test.go @@ -128,6 +128,19 @@ func TestParseTemplate_BuilderWithName(t *testing.T) { builder, ok := result.Builders["bob"] assert.True(ok, "should have bob builder") assert.Equal(builder.Type, "amazon-ebs", "builder should be amazon-ebs") + + rawConfig := builder.rawConfig + if rawConfig == nil { + t.Fatal("missing builder raw config") + } + + expected := map[string]interface{}{ + "type": "amazon-ebs", + } + + if !reflect.DeepEqual(rawConfig, expected) { + t.Fatalf("bad raw: %#v", rawConfig) + } } func TestParseTemplate_BuilderWithConflictingName(t *testing.T) { From 40897fdfc2dad785db470d1bd14e5de10dcb26f8 Mon Sep 17 00:00:00 2001 From: Julian Phillips Date: Fri, 19 Jul 2013 15:36:13 +0100 Subject: [PATCH 2/2] packer/template: Remove name from builder rawConfig This prevents the builder from rejecting the name (which it doesn't know about) when validating the config. --- packer/template.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packer/template.go b/packer/template.go index 5f05962dc..995d66342 100644 --- a/packer/template.go +++ b/packer/template.go @@ -161,6 +161,10 @@ func ParseTemplate(data []byte) (t *Template, err error) { continue } + // Now that we have the name, remove it from the config - as the builder + // itself doesn't know about, and it will cause a validation error. + delete(v, "name") + raw.rawConfig = v t.Builders[raw.Name] = raw