diff --git a/helper/schema/resource.go b/helper/schema/resource.go index fbc75bc1c2..8290ba5035 100644 --- a/helper/schema/resource.go +++ b/helper/schema/resource.go @@ -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 diff --git a/helper/schema/resource_test.go b/helper/schema/resource_test.go index 22bfd1b8cf..60b49619bf 100644 --- a/helper/schema/resource_test.go +++ b/helper/schema/resource_test.go @@ -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 {