Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .changelog/472.txt
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
```release-note:enhancement
datasource: The `DataSource` type `GetSchema` and `TypeName` methods will be required in the next version.
datasource: The `DataSource` type `GetSchema` and `Metadata` methods will be required in the next version.
```

```release-note:note
provider: The `DataSourceType` type has been deprecated in preference of moving the `GetSchema` method to the `datasource.DataSource` type and optionally implementing the `NewResource` method logic to a new `Configure` method. The `DataSourceType` type will be removed in the next version.
```

```release-note:note
provider: The `Provider` type `GetDataSources` method has been deprecated in preference of the `DataSources` method. All `datasource.DataSource` types must implement the `TypeName` method after migrating. Support for the `GetDataSources` method will be removed in the next version.
provider: The `Provider` type `GetDataSources` method has been deprecated in preference of the `DataSources` method. All `datasource.DataSource` types must implement the `Metadata` method after migrating. Support for the `GetDataSources` method will be removed in the next version.
```

```release-note:note
provider: The `Provider` type `GetResources` method has been deprecated in preference of the `Resources` method. All `resource.Resource` types must implement the `TypeName` method after migrating. Support for the `GetResources` method will be removed in the next version.
provider: The `Provider` type `GetResources` method has been deprecated in preference of the `Resources` method. All `resource.Resource` types must implement the `Metadata` method after migrating. Support for the `GetResources` method will be removed in the next version.
```

```release-note:note
provider: The `ResourceType` type has been deprecated in preference of moving the `GetSchema` method to the `resource.Resource` type and optionally implementing the `NewResource` method logic to a new `Configure` method. The `ResourceType` type will be removed in the next version.
```

```release-note:enhancement
resource: The `Resource` type `GetSchema` and `TypeName` methods will be required in the next version.
resource: The `Resource` type `GetSchema` and `Metadata` methods will be required in the next version.
```

```release-note:enhancement
datasource: Added `DataSource` type `Configure`, `GetSchema`, and `TypeName` method support
datasource: Added `DataSource` type `Configure`, `GetSchema`, and `Metadata` method support
```

```release-note:enhancement
Expand All @@ -35,9 +35,9 @@ provider: Added `ConfigureResponse` type `ResourceData` field, which will set th
```

```release-note:enhancement
provider: Added `Provider` type `Metadata` method support, which the `MetadataResponse.TypeName` field will set the `datasource.TypeNameRequest.ProviderTypeName` and `resource.TypeNameRequest.ProviderTypeName` fields
provider: Added `Provider` type `Metadata` method support, which the `MetadataResponse.TypeName` field will set the `datasource.MetadataRequest.ProviderTypeName` and `resource.MetadataRequest.ProviderTypeName` fields
```

```release-note:enhancement
resource: Added `Resource` type `Configure`, `GetSchema`, and `TypeName` method support
resource: Added `Resource` type `Configure`, `GetSchema`, and `Metadata` method support
```
14 changes: 7 additions & 7 deletions datasource/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,18 @@ type DataSourceWithGetSchema interface {
GetSchema(context.Context) (tfsdk.Schema, diag.Diagnostics)
}

// DataSourceWithTypeName is an interface type that extends DataSource to
// return its data source type name. For example, if the provider is named
// examplecloud and the data source reads a thing, this should return
// examplecloud_thing.
// DataSourceWithMetadata is an interface type that extends DataSource to
// return metadata, such as its data source type name. For example, if the
// provider is named examplecloud and the data source reads a thing, this
// should return examplecloud_thing.
//
// This method will be required in the DataSource interface a future release.
type DataSourceWithTypeName interface {
type DataSourceWithMetadata interface {
DataSource

// TypeName should return the full name of the data source, such as
// Metadata should return the full name of the data source, such as
// examplecloud_thing.
TypeName(context.Context, TypeNameRequest, *TypeNameResponse)
Metadata(context.Context, MetadataRequest, *MetadataResponse)
}

// DataSourceWithValidateConfig is an interface type that extends DataSource to include imperative validation.
Expand Down
14 changes: 7 additions & 7 deletions datasource/type_name.go → datasource/metadata.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package datasource

// TypeNameRequest represents a request for the DataSource to return its type
// name. An instance of this request struct is supplied as an argument to the
// DataSource type TypeName method.
type TypeNameRequest struct {
// MetadataRequest represents a request for the DataSource to return metadata,
// such as its type name. An instance of this request struct is supplied as an
// argument to the DataSource type Metadata method.
type MetadataRequest struct {
// ProviderTypeName is the string returned from
// [provider.MetadataResponse.TypeName], if the Provider type implements
// the Metadata method. This string should prefix the DataSource type name
// with an underscore in the response.
ProviderTypeName string
}

// TypeNameResponse represents a response to a TypeNameRequest. An
// MetadataResponse represents a response to a MetadataRequest. An
// instance of this response struct is supplied as an argument to the
// DataSource type TypeName method.
type TypeNameResponse struct {
// DataSource type Metadata method.
type MetadataResponse struct {
// TypeName should be the full data source type, including the provider
// type prefix and an underscore. For example, examplecloud_thing.
TypeName string
Expand Down
24 changes: 12 additions & 12 deletions internal/fwserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,28 +186,28 @@ func (s *Server) DataSourceFuncs(ctx context.Context) (map[string]func() datasou
for _, dataSourceFunc := range dataSourceFuncsSlice {
dataSource := dataSourceFunc()

dataSourceWithTypeName, ok := dataSource.(datasource.DataSourceWithTypeName)
dataSourceWithMetadata, ok := dataSource.(datasource.DataSourceWithMetadata)

if !ok {
s.dataSourceTypesDiags.AddError(
"Data Source Type Name Missing",
fmt.Sprintf("The %T DataSource in the provider DataSources method results is missing the TypeName method. ", dataSource)+
fmt.Sprintf("The %T DataSource in the provider DataSources method results is missing the Metadata method. ", dataSource)+
"This is always an issue with the provider and should be reported to the provider developers.",
)
continue
}

dataSourceTypeNameReq := datasource.TypeNameRequest{
dataSourceTypeNameReq := datasource.MetadataRequest{
ProviderTypeName: s.providerTypeName,
}
dataSourceTypeNameResp := datasource.TypeNameResponse{}
dataSourceTypeNameResp := datasource.MetadataResponse{}

dataSourceWithTypeName.TypeName(ctx, dataSourceTypeNameReq, &dataSourceTypeNameResp)
dataSourceWithMetadata.Metadata(ctx, dataSourceTypeNameReq, &dataSourceTypeNameResp)

if dataSourceTypeNameResp.TypeName == "" {
s.dataSourceTypesDiags.AddError(
"Data Source Type Name Missing",
fmt.Sprintf("The %T DataSource returned an empty string from the TypeName method. ", dataSource)+
fmt.Sprintf("The %T DataSource returned an empty string from the Metadata method. ", dataSource)+
"This is always an issue with the provider and should be reported to the provider developers.",
)
continue
Expand Down Expand Up @@ -460,28 +460,28 @@ func (s *Server) ResourceFuncs(ctx context.Context) (map[string]func() resource.
for _, resourceFunc := range resourceFuncsSlice {
res := resourceFunc()

resourceWithTypeName, ok := res.(resource.ResourceWithTypeName)
resourceWithMetadata, ok := res.(resource.ResourceWithMetadata)

if !ok {
s.resourceTypesDiags.AddError(
"Resource Type Name Missing",
fmt.Sprintf("The %T Resource in the provider Resources method results is missing the TypeName method. ", res)+
fmt.Sprintf("The %T Resource in the provider Resources method results is missing the Metadata method. ", res)+
"This is always an issue with the provider and should be reported to the provider developers.",
)
continue
}

resourceTypeNameReq := resource.TypeNameRequest{
resourceTypeNameReq := resource.MetadataRequest{
ProviderTypeName: s.providerTypeName,
}
resourceTypeNameResp := resource.TypeNameResponse{}
resourceTypeNameResp := resource.MetadataResponse{}

resourceWithTypeName.TypeName(ctx, resourceTypeNameReq, &resourceTypeNameResp)
resourceWithMetadata.Metadata(ctx, resourceTypeNameReq, &resourceTypeNameResp)

if resourceTypeNameResp.TypeName == "" {
s.resourceTypesDiags.AddError(
"Resource Type Name Missing",
fmt.Sprintf("The %T Resource returned an empty string from the TypeName method. ", res)+
fmt.Sprintf("The %T Resource returned an empty string from the Metadata method. ", res)+
"This is always an issue with the provider and should be reported to the provider developers.",
)
continue
Expand Down
Loading