helper/config: error if unused keys

This commit is contained in:
Mitchell Hashimoto 2015-05-27 11:34:47 -07:00
parent becd6dacd7
commit bdb9bd7dc5
1 changed files with 19 additions and 0 deletions

View File

@ -1,8 +1,12 @@
package config package config
import ( import (
"fmt"
"reflect" "reflect"
"sort"
"strings"
"github.com/hashicorp/go-multierror"
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
"github.com/mitchellh/packer/template/interpolate" "github.com/mitchellh/packer/template/interpolate"
) )
@ -70,6 +74,21 @@ func Decode(target interface{}, config *DecodeOpts, raws ...interface{}) error {
} }
} }
// If we have unused keys, it is an error
if len(md.Unused) > 0 {
var err error
sort.Strings(md.Unused)
for _, unused := range md.Unused {
if unused != "type" && !strings.HasPrefix(unused, "packer_") {
err = multierror.Append(err, fmt.Errorf(
"unknown configuration key: %q", unused))
}
}
if err != nil {
return err
}
}
return nil return nil
} }