Skip to content

Commit 98b1531

Browse files
authored
list: update code example for list to set identity data (#1025)
Currently this code example works without issues, but a recent validation change in framework means that this will begin to return an error since it isn't valid to return a list result with an identity containing all null values. hashicorp/terraform-plugin-framework#1230
2 parents d39e743 + 50cee0b commit 98b1531

File tree

1 file changed

+11
-0
lines changed
  • content/terraform-plugin-sdk/v2.38.x/docs/plugin/sdkv2/resources

1 file changed

+11
-0
lines changed

content/terraform-plugin-sdk/v2.38.x/docs/plugin/sdkv2/resources/list.mdx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,17 @@ func (r *ThingListResource) List(ctx context.Context, req list.ListRequest, stre
9696
// Set the ID of the resource for the ResourceData object
9797
rd.SetId("a_unique_id_related_to_the_thing")
9898

99+
// Get the existing identity data from ResourceData and set relevant identity attributes
100+
identity, err := rd.Identity()
101+
if err != nil {
102+
result.Diagnostics.AddError(
103+
"Retrieving identity data",
104+
"An error was encountered when retrieving the identity data: "+err.Error(),
105+
)
106+
}
107+
108+
identity.Set("an_identity_attribute", thing.IdentityAttribute)
109+
99110
// Set the attributes of interest into the resource state
100111
rd.Set("name", thing.Name)
101112
rd.Set("attribute_one", thing.AttributeOne)

0 commit comments

Comments
 (0)