-
Notifications
You must be signed in to change notification settings - Fork 768
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
[Feature Request] Authoritative repository access management #395
Comments
In case it may help somebody we ended with this hack on top of a hack. locals {
members = toset([
"userA",
])
owners = toset([
"userB",
])
all_members = setunion(local.owners, local.members)
existing_members = toset(data.github_organization.main.members)
unmanaged_members = setsubtract(local.existing_members, local.all_members)
}
data "github_organization" "main" {
name = "<your-org>"
}
resource "github_membership" "main" {
for_each = setunion(local.members, local.owners)
username = each.value
role = contains(local.owners, each.value) ? "admin" : "member"
}
// The GitHub provider is not authoritative for the members of the organization
// and Terraform does not support raising exceptions so we have to hack this check.
// https://github.com/integrations/terraform-provider-github/issues/395
// https://github.com/hashicorp/terraform/issues/15469#issuecomment-814789329
resource "github_membership" "unmanaged_members_this_should_be_empty" {
for_each = local.unmanaged_members
username = each.value
role = "member"
}
resource "null_resource" "unmanaged_members" {
count = length(local.unmanaged_members) == 0 ? 0 : "There are members who are not managed by Terraform. Comment out this resource to find who. The last one will surprise you!"
}
It can be refatored/modified into a module to manage team memberships. |
Just opened a PR for this issue, still working on tests. |
@jcudit could someone take a look at the linked PR and let me know if this is something you'd be open to merging? |
cc @kfcampbell maybe? The PR is now complete with tests. |
@maroux Is your PR intended to cover team access as well, or just individual users? What I'm hoping will eventually be part of this provider is a resource where there's one instance of that resource per repository and it covers both team and user(/collaborator) access in an authoritative manner. (Everything that's not a GitHub App and not inherited from the organization level.) |
@eriksw both teams and individual users. Example config:
|
👋 Hey Friends, this issue has been automatically marked as |
Please don't close this until an authoritative resource is available. |
* Add resource for authoritative repo access management Fixes #395 * fixes after testing * Tests * Bump to v48 * docs * review comments * also add line to github_team_repository * env * support for custom role and move to using slug instead of team id * v50 * more v50 * inverse * Vague function rename --------- Co-authored-by: Keegan Campbell <me@kfcampbell.com> Co-authored-by: Nick Floyd <139819+nickfloyd@users.noreply.github.com>
) * Add resource for authoritative repo access management Fixes integrations#395 * fixes after testing * Tests * Bump to v48 * docs * review comments * also add line to github_team_repository * env * support for custom role and move to using slug instead of team id * v50 * more v50 * inverse * Vague function rename --------- Co-authored-by: Keegan Campbell <me@kfcampbell.com> Co-authored-by: Nick Floyd <139819+nickfloyd@users.noreply.github.com>
Currently, there appears to be no way to authoritatively manage repository permissions using the GitHub terraform provider.
My use case is that there are repositories that have been created over the years, that have been imported into management by terraform, but these repositories have miscellaneous grants of read/admin/write permissions to arbitrary teams and users. (Most commonly, 'admin' to the user that initially created the repo, but there's also cases like read access being granted to a contract pentester that nobody remembered to revoke, etc...)
github_team_repository
andgithub_repository_collaborator
exist, but they are only additive: the absence of a resource setting the access for a team/user will not remove that user's access.It would be great if there was an equivalent to google_project_iam_policy — something where I can declare what users and teams should have what levels of access, and that upon apply will remove all other access.
The text was updated successfully, but these errors were encountered: