mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-11 08:05:33 -06:00
schema: Make validation more strict
This commit is contained in:
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…
Reference in New Issue
Block a user