diff --git a/helper/config/decode.go b/helper/config/decode.go index b9dafc915..af4ca1aa2 100644 --- a/helper/config/decode.go +++ b/helper/config/decode.go @@ -1,8 +1,12 @@ package config import ( + "fmt" "reflect" + "sort" + "strings" + "github.com/hashicorp/go-multierror" "github.com/mitchellh/mapstructure" "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 }