Skip to content

Commit

Permalink
provider: Deprecate DataSourceType, ResourceType, Provider type…
Browse files Browse the repository at this point in the history
… `GetDataSources`, and `Provider` type `GetResources` (#472)

Reference: #441
Reference: #442

The goal of this change is twofold:

- Deprecate the separate `DataSourceType` and `ResourceType` types.
- Enable `DataSource` and `Resource` to be self-documenting with respects to their type name.

Removing `DataSourceType` and `ResourceType` simplifies provider implementations and gives developers the choice of whether or not to configure extra data in their `DataSource` and `Resource` implementations by adding the optional `Configure` method. This data is no longer required to be the `provider.Provider` itself, but rather can be any type such as a provider-defined structure or vendor-supplied client type.

Enabling `DataSource` and `Resource` type name handling within the implementation allows provider developers to further split out their data source and resource code across package boundaries without repeated map addition logic.

Given this framework version 0.11.1 code (which generally is split across Go files/packages, but shown altogether here for brevity):

```go
var _ provider.Provider = &ExampleProvider{}

type ExampleProvider struct{
  configured bool
  // ... additional remote client fields, etc.
}

func (p ExampleProvider) GetDataSources(ctx context.Context) (map[string]provider.DataSourceType, diag.Diagnostics) {
	return map[string]provider.DataSourceType{
		"example_thing": ThingDataSourceType{},
	}, nil
}

func (p ExampleProvider) GetResources(ctx context.Context) (map[string]provider.ResourceType, diag.Diagnostics) {
	return map[string]provider.ResourceType{
		"example_thing": ThingResourceType{},
	}, nil
}

func (p ExampleProvider) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) { /* ... */ }

func (p *ExampleProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) {
  // ... remote client setup, etc.
  p.configured = true
}

var _ provider.DataSourceType = ThingDataSourceType{}
var _ datasource.DataSource = ThingDataSource{}

type ThingDataSourceType struct{}

type ThingDataSource struct{
  provider ExampleProvider
}

func (t ThingDataSourceType) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) { /* ... */ }

func (t ThingDataSourceType) NewDataSource(ctx context.Context, p provider.Provider) (datasource.DataSource, diag.Diagnostics) {
  return ThingDataSource{
    provider: p.(ExampleProvider), // unchecked type assertion shown for brevity
  }
}

func (d ThingDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
  // e.g. d.provider.Client.ReadThing()
}

var _ provider.ResourceType = ThingResourceType{}
var _ resource.Resource = ThingResource{}

type ThingResourceType struct{}

type ThingResource struct{
  provider ExampleProvider
}

func (t ThingResourceType) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) { /* ... */ }

func (t ThingResourceType) NewResource(ctx context.Context, p provider.Provider) (resource.Resource, diag.Diagnostics) {
  return ThingResource{
    provider: p.(ExampleProvider), // unchecked type assertion shown for brevity
  }
}

func (r ThingResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
  // e.g. r.provider.Client.CreateThing()
}

func (r ThingResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
  // e.g. r.provider.Client.DeleteThing()
}

func (r ThingResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
  // e.g. r.provider.Client.ReadThing()
}

func (r ThingResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
  // e.g. r.provider.Client.UpdateThing()
}
```

Could be migrated as:

```go
type ExampleClient struct {
  // client/data fields OR just use the vendor client type directly instead of this new type
}

var _ provider.Provider = &ExampleProvider{}

type ExampleProvider struct{
  // setting client, etc. fields here is now completely optional,
  // if you want to configure data sources and resource with _this_ type
}

func (p ExampleProvider) Metadata(ctx context.Context, req provider.MetadataRequest, resp *provider.MetadataResponse) {
  // make available in DataSource and Resource type TypeName methods
  resp.TypeName = "example"
}

func (p ExampleProvider) DataSources(ctx context.Context) []func() datasource.DataSource {
  return []func() datasource.DataSource{
		NewThingDataSource,
	}
}

func (p ExampleProvider) Resources(ctx context.Context) []func() resource.Resource {
  return []func() resource.Resource{
		NewThingResource,
	}
}

func (p ExampleProvider) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) { /* ... */ }

func (p *ExampleProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) {
  client := &ExampleClient{} // OR existing vendor type OR p itself
  resp.DataSourceData = client
  resp.ResourceData = client
}

var _ datasource.DataSource = &ThingDataSource{}

func NewThingDataSource() datasource.DataSource {
  return &ThingDataSource{}
}

type ThingDataSource struct{
  client *ExampleClient
}

func (d *ThingDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
  resp.TypeName = req.ProviderTypeName + "_thing"
}

func (d *ThingDataSource) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) { /* ... */ }

func (d *ThingDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse)  {
  d.client = req.ProviderData.(*ExampleClient) // unchecked type assertion shown for brevity
}

func (d *ThingDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
  // e.g. d.client.ReadThing()
}

var _ resource.Resource = &ThingResource{}

func NewThingResource() resource.Resource {
  return &ThingResource{}
}

type ThingResource struct{
  client *ExampleClient
}

func (r *ThingResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
  resp.TypeName = req.ProviderTypeName + "_thing"
}

func (r *ThingResource) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) { /* ... */ }

func (r *ThingResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
  r.client = req.ProviderData.(*ExampleClient) // unchecked type assertion shown for brevity
}

func (r *ThingResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
  // e.g. r.client.CreateThing()
}

func (r *ThingResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
  // e.g. r.client.DeleteThing()
}

func (r *ThingResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
  // e.g. r.client.ReadThing()
}

func (r *ThingResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
  // e.g. r.client.UpdateThing()
}
```

Some additional implementation notes:

- The new `Provider` type `Metadata` method is called at the beginning of the `GetProviderSchema` RPC and populates the provider type name for data source and resource type name requests.
- The framework server will automatically validate against duplicate type names, missing type names, and missing schemas when using the new `Provider` type `DataSources` and `Resources` methods.
- The new `DataSource` and `Resource` type `Configure` methods are automatically called where the framework server previously called the `DataSourceType` type `NewDataSource` method and `ResourceType` type `NewResource` method.
  • Loading branch information
bflad committed Sep 12, 2022
1 parent ff9c66b commit 7541ab1
Show file tree
Hide file tree
Showing 136 changed files with 8,285 additions and 4,617 deletions.
43 changes: 43 additions & 0 deletions .changelog/472.txt
@@ -0,0 +1,43 @@
```release-note:enhancement
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 `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 `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:note
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 `Metadata` method support
```

```release-note:enhancement
provider: Added `ConfigureResponse` type `DataSourceData` field, which will set the `datasource.ConfigureRequest.ProviderData` field
```

```release-note:enhancement
provider: Added `ConfigureResponse` type `ResourceData` field, which will set the `resource.ConfigureRequest.ProviderData` field
```

```release-note:enhancement
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 `Metadata` method support
```
31 changes: 31 additions & 0 deletions datasource/configure.go
@@ -0,0 +1,31 @@
package datasource

import (
"github.com/hashicorp/terraform-plugin-framework/diag"
)

// ConfigureRequest represents a request for the provider to configure a data
// source, i.e., set provider-level data or clients. An instance of this
// request struct is supplied as an argument to the DataSource type Configure
// method.
type ConfigureRequest struct {
// ProviderData is the data set in the
// [provider.ConfigureResponse.DataSourceData] field. This data is
// provider-specifc and therefore can contain any necessary remote system
// clients, custom provider data, or anything else pertinent to the
// functionality of the DataSource.
//
// This data is only set after the ConfigureProvider RPC has been called
// by Terraform.
ProviderData any
}

// ConfigureResponse represents a response to a ConfigureRequest. An
// instance of this response struct is supplied as an argument to the
// DataSource type Configure method.
type ConfigureResponse struct {
// Diagnostics report errors or warnings related to configuring of the
// Datasource. An empty slice indicates a successful operation with no
// warnings or errors generated.
Diagnostics diag.Diagnostics
}
48 changes: 47 additions & 1 deletion datasource/data_source.go
@@ -1,12 +1,18 @@
package datasource

import "context"
import (
"context"

"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
)

// DataSource represents an instance of a data source type. This is the core
// interface that all data sources must implement.
//
// Data sources can optionally implement these additional concepts:
//
// - Configure: Include provider-level data or clients.
// - Validation: Schema-based via tfsdk.Attribute or entire configuration
// via DataSourceWithConfigValidators or DataSourceWithValidateConfig.
type DataSource interface {
Expand All @@ -16,6 +22,22 @@ type DataSource interface {
Read(context.Context, ReadRequest, *ReadResponse)
}

// DataSourceWithConfigure is an interface type that extends DataSource to
// include a method which the framework will automatically call so provider
// developers have the opportunity to setup any necessary provider-level data
// or clients in the DataSource type.
//
// This method is intended to replace the provider.DataSourceType type
// NewDataSource method in a future release.
type DataSourceWithConfigure interface {
DataSource

// Configure enables provider-level data or clients to be set in the
// provider-defined DataSource type. It is separately executed for each
// ReadDataSource RPC.
Configure(context.Context, ConfigureRequest, *ConfigureResponse)
}

// DataSourceWithConfigValidators is an interface type that extends DataSource to include declarative validations.
//
// Declaring validation using this methodology simplifies implmentation of
Expand All @@ -31,6 +53,30 @@ type DataSourceWithConfigValidators interface {
ConfigValidators(context.Context) []ConfigValidator
}

// DataSourceWithGetSchema is an interface type that extends DataSource to
// return its schema definition.
//
// This method will be required in the DataSource interface in a future
// release.
type DataSourceWithGetSchema interface {
// GetSchema returns the schema for this data source.
GetSchema(context.Context) (tfsdk.Schema, diag.Diagnostics)
}

// 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 DataSourceWithMetadata interface {
DataSource

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

// DataSourceWithValidateConfig is an interface type that extends DataSource to include imperative validation.
//
// Declaring validation using this methodology simplifies one-off
Expand Down
10 changes: 4 additions & 6 deletions datasource/doc.go
Expand Up @@ -5,14 +5,12 @@
// to offer practitioners a read-only source of information, which is saved
// into the Terraform state and can be referenced by other parts of a
// configuration. Data sources are defined by a data source type/name, such as
// "example_thing", a schema representing the structure and data types of
// "examplecloud_thing", a schema representing the structure and data types of
// configuration and state, and read logic.
//
// The main starting point for implementations in this package is the
// DataSource type which represents an instance of a data source type that has
// its own configuration, read logic, and state. A DataSource is instantiated
// from a provider.DataSourceType type NewDataSource method, which also defines
// the data source schema. The provider.DataSourceType types are referenced by
// a provider.Provider type GetDataSources method, which enables the data
// source for practitioner and testing usage.
// its own configuration, read logic, and state. The DataSource implementations
// are referenced by a [provider.Provider] type DataSources method, which
// enables the data source for practitioner and testing usage.
package datasource
21 changes: 21 additions & 0 deletions datasource/metadata.go
@@ -0,0 +1,21 @@
package datasource

// 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
}

// MetadataResponse represents a response to a MetadataRequest. An
// instance of this response struct is supplied as an argument to the
// 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
}
6 changes: 3 additions & 3 deletions internal/fromproto5/applyresourcechange.go
Expand Up @@ -9,12 +9,12 @@ import (
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/internal/fwserver"
"github.com/hashicorp/terraform-plugin-framework/internal/privatestate"
"github.com/hashicorp/terraform-plugin-framework/provider"
"github.com/hashicorp/terraform-plugin-framework/resource"
)

// ApplyResourceChangeRequest returns the *fwserver.ApplyResourceChangeRequest
// equivalent of a *tfprotov5.ApplyResourceChangeRequest.
func ApplyResourceChangeRequest(ctx context.Context, proto5 *tfprotov5.ApplyResourceChangeRequest, resourceType provider.ResourceType, resourceSchema fwschema.Schema, providerMetaSchema fwschema.Schema) (*fwserver.ApplyResourceChangeRequest, diag.Diagnostics) {
func ApplyResourceChangeRequest(ctx context.Context, proto5 *tfprotov5.ApplyResourceChangeRequest, resource resource.Resource, resourceSchema fwschema.Schema, providerMetaSchema fwschema.Schema) (*fwserver.ApplyResourceChangeRequest, diag.Diagnostics) {
if proto5 == nil {
return nil, nil
}
Expand All @@ -37,7 +37,7 @@ func ApplyResourceChangeRequest(ctx context.Context, proto5 *tfprotov5.ApplyReso

fw := &fwserver.ApplyResourceChangeRequest{
ResourceSchema: resourceSchema,
ResourceType: resourceType,
Resource: resource,
}

config, configDiags := Config(ctx, proto5.Config, resourceSchema)
Expand Down
6 changes: 3 additions & 3 deletions internal/fromproto5/applyresourcechange_test.go
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/internal/fwserver"
"github.com/hashicorp/terraform-plugin-framework/internal/privatestate"
"github.com/hashicorp/terraform-plugin-framework/provider"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
)
Expand Down Expand Up @@ -57,7 +57,7 @@ func TestApplyResourceChangeRequest(t *testing.T) {
testCases := map[string]struct {
input *tfprotov5.ApplyResourceChangeRequest
resourceSchema fwschema.Schema
resourceType provider.ResourceType
resource resource.Resource
providerMetaSchema fwschema.Schema
expected *fwserver.ApplyResourceChangeRequest
expectedDiagnostics diag.Diagnostics
Expand Down Expand Up @@ -253,7 +253,7 @@ func TestApplyResourceChangeRequest(t *testing.T) {
t.Run(name, func(t *testing.T) {
t.Parallel()

got, diags := fromproto5.ApplyResourceChangeRequest(context.Background(), testCase.input, testCase.resourceType, testCase.resourceSchema, testCase.providerMetaSchema)
got, diags := fromproto5.ApplyResourceChangeRequest(context.Background(), testCase.input, testCase.resource, testCase.resourceSchema, testCase.providerMetaSchema)

if diff := cmp.Diff(got, testCase.expected, cmp.AllowUnexported(privatestate.ProviderData{})); diff != "" {
t.Errorf("unexpected difference: %s", diff)
Expand Down
10 changes: 5 additions & 5 deletions internal/fromproto5/importresourcestate.go
Expand Up @@ -6,15 +6,15 @@ import (
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/internal/fwserver"
"github.com/hashicorp/terraform-plugin-framework/provider"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
"github.com/hashicorp/terraform-plugin-go/tftypes"
)

// ImportResourceStateRequest returns the *fwserver.ImportResourceStateRequest
// equivalent of a *tfprotov5.ImportResourceStateRequest.
func ImportResourceStateRequest(ctx context.Context, proto5 *tfprotov5.ImportResourceStateRequest, resourceType provider.ResourceType, resourceSchema fwschema.Schema) (*fwserver.ImportResourceStateRequest, diag.Diagnostics) {
func ImportResourceStateRequest(ctx context.Context, proto5 *tfprotov5.ImportResourceStateRequest, resource resource.Resource, resourceSchema fwschema.Schema) (*fwserver.ImportResourceStateRequest, diag.Diagnostics) {
if proto5 == nil {
return nil, nil
}
Expand All @@ -40,9 +40,9 @@ func ImportResourceStateRequest(ctx context.Context, proto5 *tfprotov5.ImportRes
Raw: tftypes.NewValue(resourceSchema.Type().TerraformType(ctx), nil),
Schema: tfsdkSchema(resourceSchema),
},
ID: proto5.ID,
ResourceType: resourceType,
TypeName: proto5.TypeName,
ID: proto5.ID,
Resource: resource,
TypeName: proto5.TypeName,
}

return fw, diags
Expand Down
6 changes: 3 additions & 3 deletions internal/fromproto5/importresourcestate_test.go
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/internal/fromproto5"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/internal/fwserver"
"github.com/hashicorp/terraform-plugin-framework/provider"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
Expand All @@ -36,7 +36,7 @@ func TestImportResourceStateRequest(t *testing.T) {
testCases := map[string]struct {
input *tfprotov5.ImportResourceStateRequest
resourceSchema fwschema.Schema
resourceType provider.ResourceType
resource resource.Resource
expected *fwserver.ImportResourceStateRequest
expectedDiagnostics diag.Diagnostics
}{
Expand Down Expand Up @@ -92,7 +92,7 @@ func TestImportResourceStateRequest(t *testing.T) {
t.Run(name, func(t *testing.T) {
t.Parallel()

got, diags := fromproto5.ImportResourceStateRequest(context.Background(), testCase.input, testCase.resourceType, testCase.resourceSchema)
got, diags := fromproto5.ImportResourceStateRequest(context.Background(), testCase.input, testCase.resource, testCase.resourceSchema)

if diff := cmp.Diff(got, testCase.expected); diff != "" {
t.Errorf("unexpected difference: %s", diff)
Expand Down
6 changes: 3 additions & 3 deletions internal/fromproto5/planresourcechange.go
Expand Up @@ -9,12 +9,12 @@ import (
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/internal/fwserver"
"github.com/hashicorp/terraform-plugin-framework/internal/privatestate"
"github.com/hashicorp/terraform-plugin-framework/provider"
"github.com/hashicorp/terraform-plugin-framework/resource"
)

// PlanResourceChangeRequest returns the *fwserver.PlanResourceChangeRequest
// equivalent of a *tfprotov5.PlanResourceChangeRequest.
func PlanResourceChangeRequest(ctx context.Context, proto5 *tfprotov5.PlanResourceChangeRequest, resourceType provider.ResourceType, resourceSchema fwschema.Schema, providerMetaSchema fwschema.Schema) (*fwserver.PlanResourceChangeRequest, diag.Diagnostics) {
func PlanResourceChangeRequest(ctx context.Context, proto5 *tfprotov5.PlanResourceChangeRequest, resource resource.Resource, resourceSchema fwschema.Schema, providerMetaSchema fwschema.Schema) (*fwserver.PlanResourceChangeRequest, diag.Diagnostics) {
if proto5 == nil {
return nil, nil
}
Expand All @@ -37,7 +37,7 @@ func PlanResourceChangeRequest(ctx context.Context, proto5 *tfprotov5.PlanResour

fw := &fwserver.PlanResourceChangeRequest{
ResourceSchema: resourceSchema,
ResourceType: resourceType,
Resource: resource,
}

config, configDiags := Config(ctx, proto5.Config, resourceSchema)
Expand Down
6 changes: 3 additions & 3 deletions internal/fromproto5/planresourcechange_test.go
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/internal/fwserver"
"github.com/hashicorp/terraform-plugin-framework/internal/privatestate"
"github.com/hashicorp/terraform-plugin-framework/provider"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
)
Expand Down Expand Up @@ -55,7 +55,7 @@ func TestPlanResourceChangeRequest(t *testing.T) {
testCases := map[string]struct {
input *tfprotov5.PlanResourceChangeRequest
resourceSchema fwschema.Schema
resourceType provider.ResourceType
resource resource.Resource
providerMetaSchema fwschema.Schema
expected *fwserver.PlanResourceChangeRequest
expectedDiagnostics diag.Diagnostics
Expand Down Expand Up @@ -223,7 +223,7 @@ func TestPlanResourceChangeRequest(t *testing.T) {
t.Run(name, func(t *testing.T) {
t.Parallel()

got, diags := fromproto5.PlanResourceChangeRequest(context.Background(), testCase.input, testCase.resourceType, testCase.resourceSchema, testCase.providerMetaSchema)
got, diags := fromproto5.PlanResourceChangeRequest(context.Background(), testCase.input, testCase.resource, testCase.resourceSchema, testCase.providerMetaSchema)

if diff := cmp.Diff(got, testCase.expected, cmp.AllowUnexported(privatestate.ProviderData{})); diff != "" {
t.Errorf("unexpected difference: %s", diff)
Expand Down
6 changes: 3 additions & 3 deletions internal/fromproto5/readdatasource.go
Expand Up @@ -3,16 +3,16 @@ package fromproto5
import (
"context"

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/internal/fwserver"
"github.com/hashicorp/terraform-plugin-framework/provider"
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
)

// ReadDataSourceRequest returns the *fwserver.ReadDataSourceRequest
// equivalent of a *tfprotov5.ReadDataSourceRequest.
func ReadDataSourceRequest(ctx context.Context, proto5 *tfprotov5.ReadDataSourceRequest, dataSourceType provider.DataSourceType, dataSourceSchema fwschema.Schema, providerMetaSchema fwschema.Schema) (*fwserver.ReadDataSourceRequest, diag.Diagnostics) {
func ReadDataSourceRequest(ctx context.Context, proto5 *tfprotov5.ReadDataSourceRequest, dataSource datasource.DataSource, dataSourceSchema fwschema.Schema, providerMetaSchema fwschema.Schema) (*fwserver.ReadDataSourceRequest, diag.Diagnostics) {
if proto5 == nil {
return nil, nil
}
Expand All @@ -34,8 +34,8 @@ func ReadDataSourceRequest(ctx context.Context, proto5 *tfprotov5.ReadDataSource
}

fw := &fwserver.ReadDataSourceRequest{
DataSource: dataSource,
DataSourceSchema: dataSourceSchema,
DataSourceType: dataSourceType,
}

config, configDiags := Config(ctx, proto5.Config, dataSourceSchema)
Expand Down

0 comments on commit 7541ab1

Please sign in to comment.