feat: add github_organization_invitation resource#3464
Open
nitinjain999 wants to merge 2 commits into
Open
Conversation
Closes integrations#2197 Adds a new resource to invite users to a GitHub organization by email address or GitHub user ID, using the CreateOrgInvitation API. This addresses the limitation of github_membership which requires the user to already be a GitHub user and cannot invite by email. Addresses all review feedback from integrations#3229: - Removed redundant d.Set("invitation_id", ...) — the resource ID is the invitation ID; a separate computed field is unnecessary - Removed unnecessary ctx = context.WithValue(ctx, ctxId, ...) calls - Fixed idempotency: when an invitation is no longer pending, Read now checks if the invitee became an org member (invitation accepted) and keeps the resource in state rather than blindly removing it, which would have caused a perpetual create loop
|
👋 Hi, and thank you for this contribution! This repo is maintained by GitHub and community members on a best-effort basis. We'll get to this as soon as we can. You can help us prioritize by joining the discussion on open issues and PRs, sharing details on the changes you need, and reviewing other contributions. 🤖 This is an automated message. |
The GitHub API always returns the invitee's email in the invitation response, even for invitee_id-based invitations. Setting email in state from the Read response caused a perpetual diff when the config used invitee_id — each plan would propose to destroy and recreate. Only set email in Read when the resource was originally created with email.
janellecanon01-lab
approved these changes
Jun 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2197
Picking up the work from #3229 (original author inactive) and addressing all maintainer review feedback.
Before the change?
github_membershiponly works when a user already has a GitHub account and is identified by their username. There was no way to invite someone to an org by email address, which is a common need when onboarding new users who may not yet have GitHub accounts.After the change?
New resource
github_organization_invitation:Changes vs #3229
All three issues flagged by @deiga are addressed, plus one additional bug found during testing:
invitation_idcomputed field removed — the resource ID already is the invitation IDctx = context.WithValue(ctx, ctxId, ...)removed from Read and Delete — not neededIsMember. If they are a member, the resource stays in state. Only if the invitee is neither pending nor a member (expired/cancelled) is the resource removed from stateinvitee_id-based invitations. The original PR setemailfrom the API response unconditionally, which caused a perpetual destroy/recreate diff wheninvitee_idwas the configured field. Nowemailis only written to state when the resource was created withemailTesting
invite_by_invitee_idPASSES verified against a real org (nitin-sv) withdeigaas the external user.invite_by_emailandinvite_with_admin_roleskip whenGH_TEST_INVITATION_EMAILis not set — they require an email address not already associated with an org member.Pull request checklist
Does this introduce a breaking change?