diff --git a/internal/provider/data_source_organization_membership.go b/internal/provider/data_source_organization_membership.go index def811eb3..895c8d7c4 100644 --- a/internal/provider/data_source_organization_membership.go +++ b/internal/provider/data_source_organization_membership.go @@ -67,6 +67,14 @@ func dataSourceTFEOrganizationMembershipRead(d *schema.ResourceData, meta interf d.SetId(orgMember.ID) } else { + orgMember, err := fetchOrganizationMemberById(context.Background(), config.Client, orgMemberID) + if err != nil { + return fmt.Errorf( + "could not find organization membership (%s) for organization %s: %w", orgMemberID, organization, err, + ) + } + + d.Set("email", orgMember.Email) d.SetId(orgMemberID) } diff --git a/internal/provider/organization_members_helpers.go b/internal/provider/organization_members_helpers.go index 0226a10ed..5b37ca32d 100644 --- a/internal/provider/organization_members_helpers.go +++ b/internal/provider/organization_members_helpers.go @@ -103,3 +103,15 @@ func fetchOrganizationMemberByNameOrEmail(ctx context.Context, client *tfe.Clien return nil, tfe.ErrResourceNotFound } + +func fetchOrganizationMemberById(ctx context.Context, client *tfe.Client, orgMemberId string) (*tfe.OrganizationMembership, error) { + orgMember, err := client.OrganizationMemberships.Read(ctx, orgMemberId) + if err != nil { + return nil, fmt.Errorf("failed to read organization membership %s: %w", orgMemberId, err) + } + if orgMember != nil { + return orgMember, nil + } + + return nil, tfe.ErrResourceNotFound +}