-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathreaddatasource.go
54 lines (40 loc) · 1.69 KB
/
readdatasource.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package fromproto5
import (
"context"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/internal/fwserver"
"github.com/hashicorp/terraform-plugin-framework/provider"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"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 *tfsdk.Schema, providerMetaSchema *tfsdk.Schema) (*fwserver.ReadDataSourceRequest, diag.Diagnostics) {
if proto5 == nil {
return nil, nil
}
var diags diag.Diagnostics
// Panic prevention here to simplify the calling implementations.
// This should not happen, but just in case.
if dataSourceSchema == nil {
diags.AddError(
"Missing DataSource Schema",
"An unexpected error was encountered when handling the request. "+
"This is always an issue in terraform-plugin-framework used to implement the provider and should be reported to the provider developers.\n\n"+
"Please report this to the provider developer:\n\n"+
"Missing schema.",
)
return nil, diags
}
fw := &fwserver.ReadDataSourceRequest{
DataSourceSchema: *dataSourceSchema,
DataSourceType: dataSourceType,
}
config, configDiags := Config(ctx, proto5.Config, dataSourceSchema)
diags.Append(configDiags...)
fw.Config = config
providerMeta, providerMetaDiags := ProviderMeta(ctx, proto5.ProviderMeta, providerMetaSchema)
diags.Append(providerMetaDiags...)
fw.ProviderMeta = providerMeta
return fw, diags
}