diff --git a/README.md b/README.md
index 1bf2807..568a53a 100644
--- a/README.md
+++ b/README.md
@@ -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`)*
+
+ 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:
@@ -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 list of all team members (when using github_team_members).
+
- [**`team_memberships`**](#output-team_memberships): *(`list(team_membership)`)*
- 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)`)*
diff --git a/README.tfdoc.hcl b/README.tfdoc.hcl
index 437d3fd..4a27d7e 100644
--- a/README.tfdoc.hcl
+++ b/README.tfdoc.hcl
@@ -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
+ }
}
}
@@ -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
}
diff --git a/main.tf b/main.tf
index cc38977..7957be7 100644
--- a/main.tf
+++ b/main.tf
@@ -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
diff --git a/outputs.tf b/outputs.tf
index 7382e86..1e50f6c 100644
--- a/outputs.tf
+++ b/outputs.tf
@@ -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
}
diff --git a/variables.tf b/variables.tf
index 65604f8..de03cc6 100644
--- a/variables.tf
+++ b/variables.tf
@@ -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
+}