diff --git a/list/list_resource.go b/list/list_resource.go index 27843833b..0186e7aad 100644 --- a/list/list_resource.go +++ b/list/list_resource.go @@ -22,15 +22,13 @@ import ( // - Validation: Schema-based or entire configuration via // ListResourceWithConfigValidators or ListResourceWithValidateConfig. type ListResource interface { - // Metadata should return the full name of the list resource such as - // examplecloud_thing. This name should match the full name of the managed - // resource to be listed; otherwise, the GetMetadata RPC will return an - // error diagnostic. - // - // The method signature is intended to be compatible with the Metadata - // method signature in the Resource interface. One implementation of - // Metadata can satisfy both interfaces. - Metadata(context.Context, resource.MetadataRequest, *resource.MetadataResponse) + // A single provider-defined type can implement the + // Create-Read-Update-Delete (CRUD) operations ([resource.Resource]) and + // the List (L) operation ([list.ListResource]). The + // [resource.ResourceMetadata] interface is embedded in both interfaces. + // This allows a single implementation of `Metadata()` to satisfy both + // interfaces without code duplication. + resource.ResourceMetadata // ListResourceConfigSchema should return the schema for list blocks. ListResourceConfigSchema(context.Context, ListResourceSchemaRequest, *ListResourceSchemaResponse) diff --git a/resource/resource.go b/resource/resource.go index b15bbb80b..6903a3496 100644 --- a/resource/resource.go +++ b/resource/resource.go @@ -26,9 +26,7 @@ import ( // Although not required, it is conventional for resources to implement the // ResourceWithImportState interface. type Resource interface { - // Metadata should return the full name of the resource, such as - // examplecloud_thing. - Metadata(context.Context, MetadataRequest, *MetadataResponse) + ResourceMetadata // Schema should return the schema for this resource. Schema(context.Context, SchemaRequest, *SchemaResponse) @@ -57,6 +55,12 @@ type Resource interface { Delete(context.Context, DeleteRequest, *DeleteResponse) } +type ResourceMetadata interface { + // Metadata should return the full name of the resource, such as + // examplecloud_thing. + Metadata(context.Context, MetadataRequest, *MetadataResponse) +} + // ResourceWithConfigure is an interface type that extends Resource to // include a method which the framework will automatically call so provider // developers have the opportunity to setup any necessary provider-level data