Getting a Value Conversion Error stating I need a struct tag for tfsdk on InsightID… but I have one set so I’m not sure I follow what it is referring to. Sample code below and error.
Code:
package insightcloudsec
import (
"context"
ics "github.allstate.com/gstoy/insightcloudsec-client-go"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
)
// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &insightDataSource{}
_ datasource.DataSourceWithConfigure = &insightDataSource{}
)
func NewInsightDataSource() datasource.DataSource {
return &insightDataSource{}
}
type insightDataSource struct {
client *ics.Client
}
type insightDataSourceModel struct {
InsightSource types.String `tfsdk:"insight_source"`
InsightID types.Int64 `tfsdk:"insight_id"`
Name types.String `tfsdk:"name"`
}
func (d *insightDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_insight"
}
func (d *insightDataSource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Diagnostics) {
return tfsdk.Schema{
Description: "Fetches the insight",
Attributes: map[string]tfsdk.Attribute{
"insight_source": {
Description: "Source of the insight - backoffice or custom",
Required: true,
Type: types.StringType,
},
"insight_id": {
Description: "Numeric identifier of the insight",
Required: true,
Type: types.Int64Type,
},
"name": {
Description: "Name of the insight",
Computed: true,
Type: types.StringType,
},
},
}, nil
}
func (d *insightDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, _ *datasource.ConfigureResponse) {
if req.ProviderData == nil {
return
}
d.client = req.ProviderData.(*ics.Client)
}
func (d *insightDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
// Read configuration data into the model
var data insightDataSourceModel
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
if resp.Diagnostics.HasError() {
return
}
// Make the Request
ret, err := d.client.GetInsight(int(data.InsightID.Value), string(data.InsightSource.Value))
if err != nil {
resp.Diagnostics.AddError(
"Unable to Read InsightCloudSec Insight",
err.Error(),
)
return
}
diags := resp.State.Set(ctx, &ret)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
}
Error:
2022-10-17T09:15:00.689-0500 [ERROR] provider.terraform-provider-insightcloudsec-pf: Response contains error diagnostic: tf_req_id=19c7b619-cf3e-764a-f2dd-66bd85373338 diagnostic_detail="An unexpected error was encountered trying to convert from struct value. This is always an error in the provider. Please report the following to the provider developer:
error retrieving field names from struct tags: : need a struct tag for "tfsdk" on InsightID" tf_proto_version=6.3 tf_provider_addr=allstate.com/com/insightcloudsec-pf @caller=/Users/*****/go/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.14.0/tfprotov6/internal/diag/diagnostics.go:55 diagnostic_attribute= @module=sdk.proto tf_data_source_type=insightcloudsec_insight diagnostic_severity=ERROR diagnostic_summary="Value Conversion Error" tf_rpc=ReadDataSource timestamp=2022-10-17T09:15:00.688-0500
2022-10-17T09:15:00.689-0500 [ERROR] vertex "data.insightcloudsec_insight.example" error: Value Conversion Error
2022-10-17T09:15:00.689-0500 [ERROR] vertex "data.insightcloudsec_insight.example (expand)" error: Value Conversion Error
2022-10-17T09:15:00.689-0500 [INFO] backend/local: plan operation completed
╷
│ Error: Value Conversion Error
│
│ with data.insightcloudsec_insight.example,
│ An unexpected error was encountered trying to convert from struct value. This is always an error in the provider. Please report the following to the provider developer:
│
│ error retrieving field names from struct tags: : need a struct tag for "tfsdk" on InsightID
╵
2022-10-17T09:15:00.692-0500 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2022-10-17T09:15:00.693-0500 [DEBUG] provider: plugin process exited: path=/Users/*****/go/bin/terraform-provider-insightcloudsec-pf pid=5439
2022-10-17T09:15:00.693-0500 [DEBUG] provider: plugin exited