You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Within my provider implementation, I am struggling to understand the correct usage of autogenerated methods to define the Set value for roles in my model.
As an example, I would have assumed that the following code would be valid:
role := autogen.RolesValue{
DatabaseName: types.StringValue(v.DatabaseName),
RoleName: types.StringValue(v.RoleName),
}
rolesSet, diagnostic := types.SetValueFrom(ctx, autogen.RolesValue{}.Type(ctx), []autogen.RolesValue{role})
... // continue by defining rolesSet in model
However, this code ends up with rolesSet having a single element with all its attributes as Null. Doing some further investigation I found that the generate RolesValue has a private state field that needs the value ValueStateKnown for attribute values to be defined correctly in the set.
To get my code to work as expected (having the state field as known), I made use of the following functions:
role := autogen.RolesValue{
DatabaseName: types.StringValue(v.DatabaseName),
RoleName: types.StringValue(v.RoleName),
}
objVal, _ := value.ToObjectValue(ctx)
newRoleValue, _ := autogen.NewRolesValue(objVal.AttributeTypes(ctx), objVal.Attributes())
rolesSet, diagnostic := types.SetValueFrom(ctx, autogen.RolesValue{}.Type(ctx), []autogen.RolesValue{newRoleValue})
... // continue by defining rolesSet in model
Possible outcomes
Improve current implementation so that there is more straight forward option for creating a nested object type with the known state field, avoiding the intermediate ToObjectValue creation.
Improve current documentation in nested blocks providing an example of how the auotgenerated methods are expected to be used, and the need for the private state field.
Please let me know if there is something I am missing for my findings.
The text was updated successfully, but these errors were encountered:
Provider code spec used for generation
Description of scenario
Within my provider implementation, I am struggling to understand the correct usage of autogenerated methods to define the Set value for
roles
in my model.As an example, I would have assumed that the following code would be valid:
However, this code ends up with rolesSet having a single element with all its attributes as Null. Doing some further investigation I found that the generate RolesValue has a private
state
field that needs the valueValueStateKnown
for attribute values to be defined correctly in the set.To get my code to work as expected (having the state field as known), I made use of the following functions:
Possible outcomes
state
field.Please let me know if there is something I am missing for my findings.
The text was updated successfully, but these errors were encountered: