Merge pull request #1626 from hashicorp/b-computed-field-validate

helper/schema: validate unknown fields with computed values [GH-1507]
This commit is contained in:
Mitchell Hashimoto 2015-04-22 16:00:08 +02:00
commit b80d6d8cf3
2 changed files with 22 additions and 1 deletions

View File

@ -1078,7 +1078,7 @@ func (m schemaMap) validateObject(
} }
// Detect any extra/unknown keys and report those as errors. // Detect any extra/unknown keys and report those as errors.
raw, _ := c.Get(k) raw, _ := c.GetRaw(k)
if m, ok := raw.(map[string]interface{}); ok { if m, ok := raw.(map[string]interface{}); ok {
for subk, _ := range m { for subk, _ := range m {
if _, ok := schema[subk]; !ok { if _, ok := schema[subk]; !ok {

View File

@ -2933,6 +2933,27 @@ func TestSchemaMap_Validate(t *testing.T) {
Err: true, Err: true,
}, },
"Invalid/unknown field with computed value": {
Schema: map[string]*Schema{
"availability_zone": &Schema{
Type: TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
},
Config: map[string]interface{}{
"foo": "${var.foo}",
},
Vars: map[string]string{
"var.foo": config.UnknownVariableValue,
},
Err: true,
},
"Computed field set": { "Computed field set": {
Schema: map[string]*Schema{ Schema: map[string]*Schema{
"availability_zone": &Schema{ "availability_zone": &Schema{