helper/schema: computed fields cannot be set

This commit is contained in:
Mitchell Hashimoto 2014-08-16 09:18:45 -07:00
parent 90f462e609
commit 3a46d21527
2 changed files with 25 additions and 2 deletions

View File

@ -279,12 +279,18 @@ func (m schemaMap) validate(
if !ok {
if schema.Required {
return nil, []error{fmt.Errorf(
"%s: required field is not set")}
"%s: required field is not set", k)}
}
return nil, nil
}
if !schema.Required && !schema.Optional {
// This is a computed-only field
return nil, []error{fmt.Errorf(
"%s: this field cannot be set", k)}
}
return m.validatePrimitive(k, raw, schema, c)
}

View File

@ -583,6 +583,7 @@ func TestSchemaMap_Validate(t *testing.T) {
Schema: map[string]*Schema{
"ingress": &Schema{
Type: TypeList,
Optional: true,
Elem: &Resource{
Schema: map[string]*Schema{
"from": &Schema{
@ -622,6 +623,22 @@ func TestSchemaMap_Validate(t *testing.T) {
Err: true,
},
// Computed field set
{
Schema: map[string]*Schema{
"availability_zone": &Schema{
Type: TypeString,
Computed: true,
},
},
Config: map[string]interface{}{
"availability_zone": "bar",
},
Err: true,
},
}
for i, tc := range cases {