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

Support membership sync for org-team #22

Merged
merged 1 commit into from
Aug 27, 2024
Merged
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
3 changes: 3 additions & 0 deletions modules/org-team/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This module creates following resources.
- `github_team`
- `github_team_settings`
- `github_team_sync_group_mapping`
- `github_team_members` (optional)
- `github_team_membership` (optional)

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Expand All @@ -30,6 +31,7 @@ No modules.
| Name | Type |
|------|------|
| [github_team.this](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/team) | resource |
| [github_team_members.some_team_members](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/team_members) | resource |
| [github_team_membership.this](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/team_membership) | resource |
| [github_team_settings.this](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/team_settings) | resource |
| [github_team_sync_group_mapping.this](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/team_sync_group_mapping) | resource |
Expand All @@ -48,6 +50,7 @@ No modules.
| <a name="input_ldap_group_dn"></a> [ldap\_group\_dn](#input\_ldap\_group\_dn) | (Optional) The LDAP Distinguished Name of the group where membership will be synchronized. Only available in GitHub Enterprise Server. | `string` | `null` | no |
| <a name="input_maintainers"></a> [maintainers](#input\_maintainers) | (Optional) A list of usernames to add users as `maintainer` role. When applied, the user will become a maintainer of the team. | `set(string)` | `[]` | no |
| <a name="input_members"></a> [members](#input\_members) | (Optional) A list of usernames to add users as `member` role. When applied, the user will become a member of the team. | `set(string)` | `[]` | no |
| <a name="input_membership_sync_enabled"></a> [membership\_sync\_enabled](#input\_membership\_sync\_enabled) | (Optional) Whether to sync the members of the team. Members added outside of the Terraform code will be removed. Defaults to `false`. | `bool` | `false` | no |
| <a name="input_parent_id"></a> [parent\_id](#input\_parent\_id) | (Optional) The ID of the parent team, if this is a nested team. | `string` | `null` | no |

## Outputs
Expand Down
33 changes: 0 additions & 33 deletions modules/org-team/main.tf
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
locals {
members = [
for member in var.members : {
username = member
role = "member"
}
]
maintainers = [
for maintainer in var.maintainers : {
username = maintainer
role = "maintainer"
}
]
membership = concat(local.members, local.maintainers)
}


###################################################
# GitHub Organization Team
###################################################
Expand Down Expand Up @@ -68,19 +51,3 @@ resource "github_team_sync_group_mapping" "this" {
}
}
}


###################################################
# Membership of GitHub Organization Team
###################################################

resource "github_team_membership" "this" {
for_each = {
for member in local.membership :
member.username => member
}

team_id = github_team.this.id
username = each.key
role = each.value.role
}
47 changes: 47 additions & 0 deletions modules/org-team/membership.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
locals {
members = [
for member in var.members : {
username = member
role = "member"
}
]
maintainers = [
for maintainer in var.maintainers : {
username = maintainer
role = "maintainer"
}
]
membership = concat(local.members, local.maintainers)
}


###################################################
# Membership of GitHub Organization Team
###################################################

resource "github_team_membership" "this" {
for_each = {
for member in(!var.membership_sync_enabled ? local.membership : []) :
member.username => member
}

team_id = github_team.this.id
username = each.key
role = each.value.role
}

resource "github_team_members" "some_team_members" {
count = var.membership_sync_enabled ? 1 : 0

team_id = github_team.this.id

dynamic "members" {
for_each = local.membership
iterator = member

content {
username = member.value.username
role = member.value.role
}
}
}
7 changes: 7 additions & 0 deletions modules/org-team/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ variable "members" {
nullable = false
}

variable "membership_sync_enabled" {
description = "(Optional) Whether to sync the members of the team. Members added outside of the Terraform code will be removed. Defaults to `false`."
type = bool
default = false
nullable = false
}

variable "identity_provider_team_sync" {
description = <<EOT
(Optional) A configuration to manage team members using your identity provider groups. `identity_provider_team_sync` block as defined below.
Expand Down
Loading