helper/schema: computed fields cannot be set
This commit is contained in:
parent
90f462e609
commit
3a46d21527
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -582,7 +582,8 @@ func TestSchemaMap_Validate(t *testing.T) {
|
|||
{
|
||||
Schema: map[string]*Schema{
|
||||
"ingress": &Schema{
|
||||
Type: TypeList,
|
||||
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 {
|
||||
|
|
Loading…
Reference in New Issue