I am building a new Terraform provider and I’m stuck at handling lists during data conversion.
This is the error when I do a terraform plan
:
│ Expected framework type from provider logic: types.ListType[basetypes.StringType] / underlying type: tftypes.List[tftypes.String]
│ Received framework type from provider logic: types.ListType[!!! MISSING TYPE !!!] / underlying type: tftypes.List[tftypes.DynamicPseudoType]
│ Path: allowed_scopes_impersonation
Here is the schema.Shema
that I am using for the resource (data source is, of course, quite similar):
func UserResourceSchema(ctx context.Context) schema.Schema {
return schema.Schema{
Attributes: map[string]schema.Attribute{
"allowed_scopes_impersonation": schema.ListAttribute{
ElementType: types.StringType,
Optional: true
Computed: true,
},
"data_scope_id": schema.StringAttribute{
Computed: true,
},
.........
}
}
}
This is the Terraform model that I’m using:
type UserResourceTFModel struct {
AllowedScopesImpersonation types.List `tfsdk:"allowed_scopes_impersonation"`
DataScopeId types.String `tfsdk:"data_scope_id"`
.........
And the corresponding JSON model:
type UserAttrs struct {
AllowedScopesImpersonation []string `json:"allowed_scopes_impersonation"`
DataScopeId string `json:"data_scope_id"`
What I am not grokking is how to build the JSON from the Terraform plan data for the list type (to send to the API) and how to then convert the JSON back to Terraform to update the state:
func (r *userResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
var plan UserResourceTFModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
if resp.Diagnostics.HasError() { return }
userAttrs := axonius.UserAttrs{
AllowedScopesImpersonation: [Here is the first problem],
DataScopeId: plan.DataScopeId.ValueString(),
.........
.........
response, err := r.client.CreateUser(clientCtx, userAttrs)
var createdUser UserResourceTFModel
createdUser.AllowedScopesImpersonation = [Here is the next problem]
createdUser.DataScopeId = types.StringValue(response.DataScopeId)
.........
resp.Diagnostics.Append(resp.State.Set(ctx, &createUser)...)
if resp.Diagnostics.HasError() { return }
Any and all help is greatly appreciated.