feat: add github_user_external_identity_by_saml data source#3268
Conversation
Add a new data source that performs a reverse external identity lookup: given a SAML NameID (typically an email address), return the linked GitHub username. This complements the existing github_user_external_identity data source which looks up SAML/SCIM identity by GitHub username. The new data source uses the GraphQL externalIdentities endpoint with the userName filter parameter instead of the login filter, enabling email-to-username resolution at plan/apply time.
|
👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with |
|
Question: this could have been an additional field in the existing data source, right? |
|
Good question — yes, it could have been. The reasoning for a new data source was:
That said, I don't have a strong opinion on this — if you'd prefer a single extended data source with |
Description
Adds a new data source
github_user_external_identity_by_samlthat performs a reverse external identity lookup: given a SAML NameID (typically an email address), it returns the linked GitHub username.This complements the existing
github_user_external_identitydata source, which looks up SAML/SCIM identity by GitHub username. The new data source enables the opposite direction — email-to-username resolution atterraform plan/applytime.Motivation
When managing GitHub organization membership via Terraform (e.g. team memberships), it's common to know users by their corporate email address but not their GitHub username. The existing
github_user_external_identitydata source requires the GitHub username as input, which creates a chicken-and-egg problem.This is particularly important for organizations that:
terraform planto re-resolve the email-to-username mapping to avoid drift from GitHub username changes (which would be a security risk in SCIM-provisioned orgs)Implementation
The implementation mirrors
github_user_external_identityclosely. The only material difference is the GraphQL query filter:externalIdentities(first: 1, login: $username)— filters by GitHub loginexternalIdentities(first: 1, userName: $userName)— filters by SAML NameIDThe
userNameparameter is documented in GitHub's platform-samples and troubleshooting docs.Example Usage
Arguments
saml_name_id(Required) — The SAML NameID (typically email) to look up.Attributes
login— The GitHub username linked to this SAML identity.username— Same aslogin.saml_identity— Map of SAML identity attributes (name_id, username, given_name, family_name).scim_identity— Map of SCIM identity attributes (username, given_name, family_name).Changes
github/data_source_github_user_external_identity_by_saml.go— New data source implementationgithub/data_source_github_user_external_identity_by_saml_test.go— Acceptance testgithub/provider.go— Register the new data sourcewebsite/docs/d/user_external_identity_by_saml.html.markdown— DocumentationTest Plan
go build ./...passesgo vet ./github/...passes