Skip to content

Commit 97588a2

Browse files
alvarorm22Alvaro Gonzalezgoruha
authored
feat: Support github_team_repository (#11)
* feat: enable github_team_repository resource * remove cross variable validation * chore: using use a composite key format * chore: create local team_repository * Add new variable to README.md * Update README.md * Update variables description * Update variables in examples --------- Co-authored-by: Alvaro Gonzalez <[email protected]> Co-authored-by: Igor Rodionov <[email protected]>
1 parent 6e67603 commit 97588a2

7 files changed

Lines changed: 78 additions & 20 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ Here is an example of using this module:
205205
| <a name="input_squash_merge_commit_title"></a> [squash\_merge\_commit\_title](#input\_squash\_merge\_commit\_title) | Squash merge commit title. Must be PR\_TITLE or COMMIT\_OR\_PR\_TITLE. | `string` | `"PR_TITLE"` | no |
206206
| <a name="input_stage"></a> [stage](#input\_stage) | ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no |
207207
| <a name="input_tags"></a> [tags](#input\_tags) | Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`).<br/>Neither the tag keys nor the tag values will be modified by this module. | `map(string)` | `{}` | no |
208-
| <a name="input_teams"></a> [teams](#input\_teams) | A map of teams and their permissions for the repository | `map(string)` | `{}` | no |
208+
| <a name="input_teams"></a> [teams](#input\_teams) | A map of teams and their permissions for the repository. This will create github_repository_collaborators resources for each team. | `map(string)` | `{}` | no |
209+
| <a name="input_team_repository"></a> [team_repository](#input\_team_repository) | A map of permissions and their teams for the repository. This will create github_team_repository resources for each team. Format: { permission = [list of teams] } | `map(list(string))` | `{}` | no |
209210
| <a name="input_template"></a> [template](#input\_template) | Template repository | <pre>object({<br/> owner = string<br/> name = string<br/> include_all_branches = optional(bool, false)<br/> })</pre> | `null` | no |
210211
| <a name="input_tenant"></a> [tenant](#input\_tenant) | ID element \_(Rarely used, not included by default)\_. A customer identifier, indicating who this instance of a resource is for | `string` | `null` | no |
211212
| <a name="input_topics"></a> [topics](#input\_topics) | List of repository topics | `list(string)` | `[]` | no |

examples/complete/main.tf

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,15 @@ module "example" {
5555
custom_properties = var.custom_properties
5656
environments = var.environments
5757

58-
variables = var.variables
59-
secrets = var.secrets
60-
deploy_keys = var.deploy_keys
61-
webhooks = var.webhooks
62-
labels = var.labels
63-
teams = var.teams
64-
users = var.users
65-
rulesets = var.rulesets
58+
variables = var.variables
59+
secrets = var.secrets
60+
deploy_keys = var.deploy_keys
61+
webhooks = var.webhooks
62+
labels = var.labels
63+
teams = var.teams
64+
team_repository = var.team_repository
65+
users = var.users
66+
rulesets = var.rulesets
6667

6768
}
6869

examples/complete/variables.tf

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,12 +402,24 @@ variable "labels" {
402402
}
403403

404404
variable "teams" {
405-
description = "A map of teams and their permissions for the repository"
405+
description = "A map of teams and their permissions for the repository. This will create github_repository_collaborators resources for each team "
406406
type = map(string)
407407
default = {}
408408
nullable = false
409409
}
410410

411+
variable "team_repository" {
412+
description = "A map of permissions and their teams for the repository. This will create github_team_repository resources for each team. Format: { permission = [list of teams] }"
413+
type = map(list(string))
414+
default = {}
415+
nullable = false
416+
417+
validation {
418+
condition = alltrue([for permission, teams in var.team_repository : contains(["pull", "triage", "push", "maintain", "admin"], permission)])
419+
error_message = "Team repository permissions must be one of: pull, triage, push, maintain, admin"
420+
}
421+
}
422+
411423
variable "users" {
412424
description = "A map of users and their permissions for the repository"
413425
type = map(string)

examples/minimum/main.tf

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ module "example" {
5353
custom_properties = var.custom_properties
5454
environments = var.environments
5555

56-
variables = var.variables
57-
secrets = var.secrets
58-
deploy_keys = var.deploy_keys
59-
webhooks = var.webhooks
60-
labels = var.labels
61-
teams = var.teams
62-
users = var.users
63-
rulesets = var.rulesets
56+
variables = var.variables
57+
secrets = var.secrets
58+
deploy_keys = var.deploy_keys
59+
webhooks = var.webhooks
60+
labels = var.labels
61+
teams = var.teams
62+
team_repository = var.team_repository
63+
users = var.users
64+
rulesets = var.rulesets
6465
}

examples/minimum/variables.tf

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,12 +377,24 @@ variable "labels" {
377377
}
378378

379379
variable "teams" {
380-
description = "A map of teams and their permissions for the repository"
380+
description = "A map of teams and their permissions for the repository. This will create github_repository_collaborators resources for each team "
381381
type = map(string)
382382
default = {}
383383
nullable = false
384384
}
385385

386+
variable "team_repository" {
387+
description = "A map of permissions and their teams for the repository. This will create github_team_repository resources for each team. Format: { permission = [list of teams] }"
388+
type = map(list(string))
389+
default = {}
390+
nullable = false
391+
392+
validation {
393+
condition = alltrue([for permission, teams in var.team_repository : contains(["pull", "triage", "push", "maintain", "admin"], permission)])
394+
error_message = "Team repository permissions must be one of: pull, triage, push, maintain, admin"
395+
}
396+
}
397+
386398
variable "users" {
387399
description = "A map of users and their permissions for the repository"
388400
type = map(string)

main.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,25 @@ resource "github_repository_collaborators" "default" {
377377
}
378378
}
379379

380+
locals {
381+
team_repository = merge([
382+
for permission, teams in var.team_repository : {
383+
for team in teams : "${team}_${permission}" => {
384+
team_id = team
385+
permission = permission
386+
}
387+
}
388+
]...)
389+
}
390+
391+
resource "github_team_repository" "default" {
392+
for_each = module.this.enabled && length(var.teams) == 0 && length(var.team_repository) > 0 ? local.team_repository : {}
393+
394+
repository = join("", github_repository.default[*].name)
395+
team_id = each.value.team_id
396+
permission = each.value.permission
397+
}
398+
380399
locals {
381400
organization_roles_map = {
382401
"maintain" = "2"

variables.tf

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,12 +408,24 @@ variable "labels" {
408408
}
409409

410410
variable "teams" {
411-
description = "A map of teams and their permissions for the repository"
411+
description = "A map of teams and their permissions for the repository. This will create github_repository_collaborators resources for each team "
412412
type = map(string)
413413
default = {}
414414
nullable = false
415415
}
416416

417+
variable "team_repository" {
418+
description = "A map of permissions and their teams for the repository. This will create github_team_repository resources for each team. Format: { permission = [list of teams] }"
419+
type = map(list(string))
420+
default = {}
421+
nullable = false
422+
423+
validation {
424+
condition = alltrue([for permission, teams in var.team_repository : contains(["pull", "triage", "push", "maintain", "admin"], permission)])
425+
error_message = "Team repository permissions must be one of: pull, triage, push, maintain, admin"
426+
}
427+
}
428+
417429
variable "users" {
418430
description = "A map of users and their permissions for the repository"
419431
type = map(string)

0 commit comments

Comments
 (0)