Skip to content

Commit

Permalink
tools/tfsdk2fw: New Go packages: hashicorp/terraform-plugin-framework…
Browse files Browse the repository at this point in the history
  • Loading branch information
ewbankkit committed Aug 17, 2022
1 parent 9c6a571 commit 37ecf3f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 6 additions & 4 deletions tools/tfsdk2fw/datasource.tmpl
Expand Up @@ -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"
Expand All @@ -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
}

Expand All @@ -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")
}
8 changes: 7 additions & 1 deletion tools/tfsdk2fw/main.go
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bytes"
"context"
_ "embed"
"flag"
"fmt"
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 37ecf3f

Please sign in to comment.