config: validate invalid variable keys
Fixes #9416 A simple change to verify that only valid keys for `variable` blocks are used.
This commit is contained in:
parent
c02b2471d6
commit
3ba9720b3e
|
@ -410,14 +410,12 @@ func loadVariablesHcl(list *ast.ObjectList) ([]*Variable, error) {
|
||||||
item.Pos(), NameRegexp)
|
item.Pos(), NameRegexp)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// Check for invalid keys
|
||||||
// TODO: catch extra fields
|
valid := []string{"type", "default", "description"}
|
||||||
// Decode into raw map[string]interface{} so we know ALL fields
|
if err := checkHCLKeys(item.Val, valid); err != nil {
|
||||||
var config map[string]interface{}
|
return nil, multierror.Prefix(err, fmt.Sprintf(
|
||||||
if err := hcl.DecodeObject(&config, item.Val); err != nil {
|
"variable[%s]:", n))
|
||||||
return nil, err
|
}
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Decode into hclVariable to get typed values
|
// Decode into hclVariable to get typed values
|
||||||
var hclVar hclVariable
|
var hclVar hclVariable
|
||||||
|
|
|
@ -67,6 +67,13 @@ func TestLoadFile_lifecycleKeyCheck(t *testing.T) {
|
||||||
t.Logf("err: %s", err)
|
t.Logf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLoadFile_varInvalidKey(t *testing.T) {
|
||||||
|
_, err := LoadFile(filepath.Join(fixtureDir, "var-invalid-key.tf"))
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("should have error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestLoadFile_resourceArityMistake(t *testing.T) {
|
func TestLoadFile_resourceArityMistake(t *testing.T) {
|
||||||
_, err := LoadFile(filepath.Join(fixtureDir, "resource-arity-mistake.tf"))
|
_, err := LoadFile(filepath.Join(fixtureDir, "resource-arity-mistake.tf"))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
variable "a" {
|
||||||
|
a = "b"
|
||||||
|
}
|
Loading…
Reference in New Issue