terraform-provider-github
terraform-provider-github copied to clipboard
github_user doesn't retrieve organization email
terraform version
Terraform v1.0.11 on darwin_amd64
- provider registry.terraform.io/hashicorp/external v2.1.0
- provider registry.terraform.io/integrations/github v4.18.2
Tested with a Full Access personal access token.
Affected Resource(s)
- github_user
Terraform Configuration Files
terraform {
required_providers {
github = {
source = "integrations/github"
version = "~> 4.0"
}
}
}
# Assumes GITHUB_TOKEN is set
provider "github" {
owner = "my-org"
}
data "github_organization_teams" "all" {}
locals {
# members = setunion(flatten(data.github_organization_teams.all.teams.*.members))
members = toset(["DavidGamba"])
}
data "github_user" "reviewers" {
for_each = local.members
username = each.key
}
output "reviewers" {
# value = [for o in data.github_user.reviewers : o.email]
value = data.github_user.reviewers
}
The output is the following:
+ reviewers = {
+ DavidGamba = {
+ avatar_url = "https://avatars.githubusercontent.com/u/xxx?v=4"
+ bio = ""
+ blog = ""
+ company = ""
+ created_at = null
+ email = ""
+ followers = 18
+ following = 19
+ gpg_keys = []
+ gravatar_id = ""
+ id = "xxx"
+ location = ""
+ login = "DavidGamba"
+ name = "David Gamba"
Actual Behavior
Organization email doesn't show up in the github_user
data block even though the org is defined in the provider.
Expected Behavior
When I query my organization for members I can clearly retrieve the email:
github_user
should retrieve the organization email.
End Goal
I want to be able to tie organizational email to github IDs.
Additional notes
I have 3 email addresses in my account. However, the UI is smart enough to only retrieve the organization email when I query for the organization members.
The github_user
resource doesn't have any other attribute that is a list of emails where I could pick one if there were multiple returned.
Yep, I get this too; I thought it was down to privileges of the GitHub App I am using, but it has the User Email ReadOnly right (amongst others).
Okay, looking into this further, I have managed to get the email address, by setting the email address in the profile (which defaults to blank).
This is because we seem to be using the following API: https://docs.github.com/en/rest/reference/users#get-the-authenticated-user
Whereas, ideally we should use this API to acquire all the email addresses: https://docs.github.com/en/rest/reference/users#list-email-addresses-for-the-authenticated-user
I'm actually after the primary sign-up email address, but doing the above would at least enable me to filter it, since the primary flag is part of the response.
@richardj-bsquare I don't think that API endpoint will work as is only gives back the emails of the currently authenticated user, this approach would require that you use the basic auth in the API call to pass the username/password for each user you want to get this information for.
👋 Hey Friends, this issue has been automatically marked as stale
because it has no recent activity. It will be closed if no further activity occurs. Please add the Status: Pinned
label if you feel that this issue needs to remain open/active. Thank you for your contributions and help in keeping things tidy!