mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-29 10:21:01 -06:00
helper/schema: CustomizeDiff allowed on writable resources only
This keeps CustomizeDiff from being defined on data sources, where it would be useless. We just catch this in InternalValidate like the rest of the CRUD functions that are not used in data sources.
This commit is contained in:
parent
2c541e8c97
commit
0c0ae3ca7c
@ -112,6 +112,8 @@ type Resource struct {
|
||||
//
|
||||
// For the most part, only computed fields can be customized by this
|
||||
// function.
|
||||
//
|
||||
// This function is only allowed on regular resources (not data sources).
|
||||
CustomizeDiff CustomizeDiffFunc
|
||||
|
||||
// Importer is the ResourceImporter implementation for this resource.
|
||||
@ -378,6 +380,11 @@ func (r *Resource) InternalValidate(topSchemaMap schemaMap, writable bool) error
|
||||
if r.Create != nil || r.Update != nil || r.Delete != nil {
|
||||
return fmt.Errorf("must not implement Create, Update or Delete")
|
||||
}
|
||||
|
||||
// CustomizeDiff cannot be defined for read-only resources
|
||||
if r.CustomizeDiff != nil {
|
||||
return fmt.Errorf("cannot implement CustomizeDiff")
|
||||
}
|
||||
}
|
||||
|
||||
tsm := topSchemaMap
|
||||
|
@ -835,6 +835,21 @@ func TestResourceInternalValidate(t *testing.T) {
|
||||
true,
|
||||
false,
|
||||
},
|
||||
|
||||
13: { // non-writable must not define CustomizeDiff
|
||||
&Resource{
|
||||
Read: func(d *ResourceData, meta interface{}) error { return nil },
|
||||
Schema: map[string]*Schema{
|
||||
"goo": &Schema{
|
||||
Type: TypeInt,
|
||||
Optional: true,
|
||||
},
|
||||
},
|
||||
CustomizeDiff: func(*ResourceDiff, interface{}) error { return nil },
|
||||
},
|
||||
false,
|
||||
true,
|
||||
},
|
||||
}
|
||||
|
||||
for i, tc := range cases {
|
||||
|
Loading…
Reference in New Issue
Block a user