schema: Make validation more strict

pull/3288/head
Radek Simko 11 years ago committed by Radek Simko
parent abe5189eb8
commit 641b701830

@ -244,7 +244,20 @@ func (r *Resource) InternalValidate(topSchemaMap schemaMap) error {
return fmt.Errorf(
"No Update defined, must set ForceNew on: %#v", nonForceNewAttrs)
}
} else {
nonUpdateableAttrs := make([]string, 0)
for k, v := range r.Schema {
if v.ForceNew || (v.Computed && !v.Optional) {
nonUpdateableAttrs = append(nonUpdateableAttrs, k)
}
}
updateableAttrs := len(r.Schema) - len(nonUpdateableAttrs)
if updateableAttrs == 0 {
return fmt.Errorf(
"All fields are ForceNew or Computed w/out Optional, Update is superfluous")
}
}
tsm = schemaMap(r.Schema)
}

@ -335,6 +335,36 @@ func TestResourceInternalValidate(t *testing.T) {
},
true,
},
// Update undefined for non-ForceNew field
{
&Resource{
Create: func(d *ResourceData, meta interface{}) error { return nil },
Schema: map[string]*Schema{
"boo": &Schema{
Type: TypeInt,
Optional: true,
},
},
},
true,
},
// Update defined for ForceNew field
{
&Resource{
Create: func(d *ResourceData, meta interface{}) error { return nil },
Update: func(d *ResourceData, meta interface{}) error { return nil },
Schema: map[string]*Schema{
"goo": &Schema{
Type: TypeInt,
Optional: true,
ForceNew: true,
},
},
},
true,
},
}
for i, tc := range cases {

Loading…
Cancel
Save