Hi
I have created a sample code by following exact foot steps given on the below article for using ListNestedAttributes
{
"subusers": [
{
"user_id": 12345678,
"username": "chida.test"
}
]
//other values to
}
My struct are like this
type Listsubusers struct {
Username types.String `tfsdk:"username"`
UserID types.Int64 `tfsdk:"user_id"`
}
type DomainsubuserResourceModel struct {
ID types.Int64 `tfsdk:"id"`
Username types.String `tfsdk:"username"`
Subusers []Listsubusers `tfsdk:"subusers"`
}
My schema will look like this
"subusers": schema.ListNestedAttribute{
Computed: true,
PlanModifiers: []planmodifier.List{
listplanmodifier.UseStateForUnknown(),
},
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"username": schema.StringAttribute{
Description: "The subuser username to be associate with the domain",
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"user_id": schema.Int64Attribute{
Description: "The subuser id to be associate with the domain",
Computed: true,
PlanModifiers: []planmodifier.Int64{
int64planmodifier.UseStateForUnknown(),
},
},
},
},
},
my create function will have code like this to set the state file
for orderItemIndex, orderItem := range domainsubuser.Subusers {
domainsubnewstate.Subusers[orderItemIndex] = Listsubusers{
Username: types.StringValue(orderItem.Username),
UserID: types.Int64Value(orderItem.UserID),
}
}
but getting below error message
Error: Value Conversion Error
An unexpected error was encountered trying to build a value. This is always an error in the provider. Please
│ report the following to the provider developer:
│
│ Received unknown value, however the target type cannot handle unknown values. Use the corresponding `types`
│ package type or a custom type that handles unknown values.
│
│ Path: subusers
│ Target Type: []sendgrid.Listsubusers
│ Suggested Type: basetypes.ListValue
Alternatively tried using Block and it update state file but that ends up an error as below
block count has changed from 0 to 1.
Please any suggestion would be really helpful.