Hello! I’m sure I’m making a very silly mistake as I’m just making my way through the terraform plugin provider tutorials but for the life of me I can’t figure out the issue.
I’m trying to define a terraform resource, I have defined the Schema method, a model struct type containing all the fields using types.String/Bool/etc
(see here for my code), and have confirmed that when calling terraform apply
the code reaches my Create method but fails for the following block:
// Retrieve values from plan
var plan lessonResourceModel
diags = req.Plan.Get(ctx, &plan)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
with error mismatch between struct and object: Object defines fields not found in struct: (proceeds to list all of my fields)
I’ve confirmed with the following snippet that req.Plan
has all the values I’m expecting:
var test types.String
diags := req.Plan.GetAttribute(ctx, path.Root("title"), &test)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
fmt.Println(test.ValueString())
But for whatever reason it thinks that lessonResourceModel
doesn’t have the fields specified (even though I defined it directly above this function). Any things I should be looking out for?