Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ability to read an organization membership by org membership id #1036

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions internal/provider/data_source_organization_membership.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,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)
}

Expand Down
12 changes: 12 additions & 0 deletions internal/provider/organization_members_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,15 @@

return nil, tfe.ErrResourceNotFound
}

func fetchOrganizationMemberById(ctx context.Context, client *tfe.Client, orgMemberId string) (*tfe.OrganizationMembership, error) {

Check failure on line 107 in internal/provider/organization_members_helpers.go

View workflow job for this annotation

GitHub Actions / lint

ST1003: func fetchOrganizationMemberById should be fetchOrganizationMemberByID (stylecheck)
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
}
Loading