func (e *Events2MetricResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Computed: true,
},
"name": schema.StringAttribute{
Required: true,
Validators: []validator.String{
stringvalidator.RegexMatches(regexp.MustCompile(`^[A-Za-z\d_:-]*$`), "Invalid metric name, name may only contain ASCII letters and digits, as well as underscores and colons."),
stringvalidator.LengthAtLeast(1),
},
MarkdownDescription: "Events2Metric name. Events2Metric names have to be unique per account.",
},
},
}
}
I defined the next correlated struct model (which I don’t even think it related to this issue) -
type Events2MetricResourceModel struct {
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
}
When I tried to run a plan with next config -
resource "coralogix_events2metric" "logs2metric" {
name = "logs2metricExample"
}
I got the next error -
> 2023-06-14T14:16:53.011+0300 [ERROR] vertex "coralogix_events2metric.logs2metric" error: Value Conversion Error
> ╷
> │ Error: Value Conversion Error
> │
> │ with coralogix_events2metric.logs2metric,
> │ An unexpected error was encountered trying to convert tftypes.Value into coralogix.Events2MetricResource. This is always an error in the provider. Please report the following to the provider developer:
> │
> │ mismatch between struct and object: Object defines fields not found in struct: id and name.
This is the beginning of the Create function, but I tried to debug, and it seems the error happens before this step.
func (e *Events2MetricResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
// Retrieve values from plan
var plan Events2MetricResourceModel
diags := req.Plan.Get(ctx, &plan)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
...
}
One thing you can do to confirm which Terraform RPC is being invoked against the provider and where the error is being generated is enable logging, e.g. adding the TF_LOG=TRACE environment variable while invoking the terraform command or go test command, such as TF_LOG=TRACE terraform apply or TF_LOG=TRACE TF_ACC=1 go test -count=1 -v ./... when performing provider acceptance testing.
For a vanilla terraform apply command a summary of the following calls are made along with the following framework functionality that gets invoked (if defined):
ValidateProviderConfig (PrepareProviderConfig in protocol version 5) - provider.Provider implementation Schema method validators, ConfigValidators method, ValidateConfig method
Without seeing the full resource implementation its hard to immediately tell why that error is being generated, but it silly as it might be, it might also be good to confirm that the Events2MetricResourceModel type definition is correctly saved on disk.