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

feat: add support to use github_team_members #65

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ See [variables.tf] and [examples/] for details and use-cases.

Default is `true`.

- [**`module_use_members`**](#var-module_use_members): *(Optional `bool`)*<a name="var-module_use_members"></a>

Wether to use github_team_members or github_team_membership.

Default is `false`.

## Module Outputs

The following attributes are exported in the outputs of the module:
Expand All @@ -207,9 +213,13 @@ The following attributes are exported in the outputs of the module:

The full team object.

- [**`team_members`**](#output-team_members): *(`list(team_members)`)*<a name="output-team_members"></a>

A list of all team members (when using github_team_members).

- [**`team_memberships`**](#output-team_memberships): *(`list(team_membership)`)*<a name="output-team_memberships"></a>

A list of all team memberships.
A list of all team memberships (when using github_team_membership).

- [**`team_repositories`**](#output-team_repositories): *(`list(team_repository)`)*<a name="output-team_repositories"></a>

Expand Down
17 changes: 16 additions & 1 deletion README.tfdoc.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,14 @@ section {
Specifies whether resources in the module will be created.
END
}

variable "module_use_members" {
type = bool
default = false
description = <<-END
Wether to use github_team_members or github_team_membership.
END
}
}
}

Expand Down Expand Up @@ -283,10 +291,17 @@ section {
END
}

output "team_members" {
type = list(team_members)
description = <<-END
A list of all team members (when using github_team_members).
END
}

output "team_memberships" {
type = list(team_membership)
description = <<-END
A list of all team memberships.
A list of all team memberships (when using github_team_membership).
END
}

Expand Down
18 changes: 17 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,24 @@ locals {
memberships = merge(local.maintainers, local.members)
}

resource "github_team_members" "team_members" {
count = var.module_enabled && var.module_use_members ? 1 : 0

team_id = try(github_team.team[0].id, null)

dynamic "members" {
for_each = { for m in local.memberships : m.username => m }
content {
username = members.value.username
role = members.value.role
}
}

depends_on = [var.module_depends_on]
}

resource "github_team_membership" "team_membership" {
for_each = var.module_enabled ? local.memberships : {}
for_each = var.module_enabled && !var.module_use_members ? local.memberships : {}

team_id = try(github_team.team[0].id, null)
username = each.value.username
Expand Down
7 changes: 6 additions & 1 deletion outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ output "team" {
value = one(github_team.team)
}

output "team_members" {
description = "A list of all team members (when using github_team_members)."
value = github_team_members.team_members
}

output "team_memberships" {
description = "A list of all team memberships."
description = "A list of all team memberships (when using github_team_membership)."
value = github_team_membership.team_membership
}

Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,9 @@ variable "module_depends_on" {
description = "(Optional) A list of external resources the module depends_on. Default is []."
default = []
}

variable "module_use_members" {
type = bool
description = "(Optional) Wether to use github_team_members or github_team_membership."
default = false
}