I am making a very simple datasource in the Terraform-plugin-framework.
Terraform wants me to use their custom types
in structs in order to modify state, like this:
type HumanModel struct {
Firstname types.String `tfsdk:"name"`
Lastname types.String `tfsdk:"owner"`
)
In my datasource, I make a request to my API, which returns a regular go struct like this:
type NetworkHumanModel struct {
Firstname string `json:"name"`
Lastname string `json:"owner"`
}
Right now, I unmarshal the object I get back from my API to my NetworkHumanModel
struct, then I convert that struct to the HumanModel
struct. Currently I do that this way:
//data = HumanModel
//response = NetworkHumanModel
data.Firstname = types.StringValue(response.Firstname)
data.Lastname = types.StringValue(response.Lastname)
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
Its a lot of manual labour to do this with bigger responses and POST requests, is there a quicker way to convert between the two structs?