From 747f260678459de998a6d0d161415a65a6743c44 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 27 Aug 2013 21:34:55 -0700 Subject: [PATCH] packer: template error if override specified for bad builder [GH-336] --- CHANGELOG.md | 2 ++ packer/template.go | 8 ++++++++ packer/template_test.go | 28 ++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 299b09302..ea9823ee4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,8 @@ IMPROVEMENTS: BUG FIXES: * core: Fixed a couple cases where a double ctrl-C could panic. +* core: Template validation fails if an override is specified for a + non-existent builder. [GH-336] * builder/amazon/instance: Remove check for ec2-ami-tools because it didn't allow absolute paths to work properly. [GH-330] * builder/digitalocean: Send a soft shutdown request so that files diff --git a/packer/template.go b/packer/template.go index a113ed06e..4ac995f5e 100644 --- a/packer/template.go +++ b/packer/template.go @@ -221,6 +221,14 @@ func ParseTemplate(data []byte) (t *Template, err error) { // actively reject them as invalid configuration. delete(v, "override") + // Verify that the override keys exist... + for name, _ := range raw.Override { + if _, ok := t.Builders[name]; !ok { + errors = append( + errors, fmt.Errorf("provisioner %d: build '%s' not found for override", i+1, name)) + } + } + raw.RawConfig = v } diff --git a/packer/template_test.go b/packer/template_test.go index 4bafa9c3a..398e48975 100644 --- a/packer/template_test.go +++ b/packer/template_test.go @@ -700,6 +700,34 @@ func TestTemplate_Build_ProvisionerOverride(t *testing.T) { assert.Equal(len(coreBuild.provisioners[0].config), 2, "should have two configs on the provisioner") } +func TestTemplate_Build_ProvisionerOverrideBad(t *testing.T) { + data := ` + { + "builders": [ + { + "name": "test1", + "type": "test-builder" + } + ], + + "provisioners": [ + { + "type": "test-prov", + + "override": { + "testNope": {} + } + } + ] + } + ` + + _, err := ParseTemplate([]byte(data)) + if err == nil { + t.Fatal("should have error") + } +} + func TestTemplateBuild_variables(t *testing.T) { data := ` {