From 37ecf3f9ac097359c7a1eb43837477e34c5620a6 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 17 Aug 2022 15:04:22 -0400 Subject: [PATCH] tools/tfsdk2fw: New Go packages: https://github.com/hashicorp/terraform-plugin-framework/pull/432. --- tools/tfsdk2fw/datasource.tmpl | 10 ++++++---- tools/tfsdk2fw/main.go | 8 +++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/tools/tfsdk2fw/datasource.tmpl b/tools/tfsdk2fw/datasource.tmpl index fcd6c58257e4..ea530ac43ae5 100644 --- a/tools/tfsdk2fw/datasource.tmpl +++ b/tools/tfsdk2fw/datasource.tmpl @@ -5,7 +5,9 @@ package {{ .PackageName }} import ( "context" + "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" @@ -16,7 +18,7 @@ func init() { } // newDataSource{{ .Name }}Type instantiates a new DataSourceType for the {{ .TFTypeName }} data source. -func newDataSource{{ .Name }}Type(ctx context.Context) (tfsdk.DataSourceType, error) { +func newDataSource{{ .Name }}Type(ctx context.Context) (provider.DataSourceType, error) { return &dataSource{{ .Name }}Type{}, nil } @@ -30,14 +32,14 @@ func (t *dataSource{{ .Name }}Type) GetSchema(context.Context) (tfsdk.Schema, di } // NewDataSource instantiates a new DataSource of this DataSourceType. -func (t *dataSource{{ .Name }}Type) NewDataSource(ctx context.Context, provider tfsdk.Provider) (tfsdk.DataSource, diag.Diagnostics) { +func (t *dataSource{{ .Name }}Type) NewDataSource(ctx context.Context, provider provider.Provider) (provider.DataSource, diag.Diagnostics) { return &dataSource{{ .Name }}{}, nil } type dataSource{{ .Name }} struct {} // Read is called when the provider must read data source values in order to update state. -// Config values should be read from the ReadDataSourceRequest and new state values set on the ReadDataSourceResponse. -func (d *dataSource{{ .Name }}) Read(ctx context.Context, request tfsdk.ReadDataSourceRequest, response *tfsdk.ReadDataSourceResponse) { +// Config values should be read from the ReadRequest and new state values set on the ReadResponse. +func (d *dataSource{{ .Name }}) Read(ctx context.Context, request datasource.ReadRequest, response *datasource.ReadResponse) { tflog.Trace(ctx, "dataSource{{ .Name }}.Read enter") } \ No newline at end of file diff --git a/tools/tfsdk2fw/main.go b/tools/tfsdk2fw/main.go index 5f43596a2acd..0c4bb682567f 100644 --- a/tools/tfsdk2fw/main.go +++ b/tools/tfsdk2fw/main.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "context" _ "embed" "flag" "fmt" @@ -54,7 +55,12 @@ func main() { Ui: ui, } - p := provider.Provider() + p, err := provider.New(context.Background()) + + if err != nil { + ui.Error(err.Error()) + os.Exit(1) + } if v := *dataSourceType; v != "" { resource, ok := p.DataSourcesMap[v]