-
Notifications
You must be signed in to change notification settings - Fork 23
/
github_team_repository.tf
62 lines (54 loc) · 2.11 KB
/
github_team_repository.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# vim:ts=2:sts=2:sw=2:et
#
# Author: Hari Sekhon
# Date: 2022-03-01 12:00:27 +0000 (Tue, 01 Mar 2022)
#
# https://github.com/HariSekhon/Terraform
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/HariSekhon
#
# ============================================================================ #
# GitHub Teams Repository Permissions
# ============================================================================ #
# manually list select repos a given team can access and then for_each it further down
locals {
devs_team_repos = [
"myrepo1",
"myrepo2",
]
}
resource "github_team_repository" "devs-team" {
permission = "push"
for_each = toset(local.devs_team_repos)
repository = each.key
team_id = github_team.devs.id
# if generated via a for_each as per adjacent github_team.tf
#team_id = github_team.team["devs"].id
}
# ============================================================================ #
# XXX: Dynamically adding team to all repos is better done in github_repo module with self references for proper dependency ordering (can't depends_on dynamic generated references, must be statically resolvable)
# works around Terraform splat expressions not supporting top-level resource globbing of 1.1.x :'-(
#
# https://github.com/hashicorp/terraform/issues/19931
#
data "external" "github_repos" {
# https://github.com/HariSekhon/DevOps-Bash-tools
program = ["/path/to/devops-bash-tools/terraform_resources.sh", "github_repository"]
}
# automatically find and grant admin on all GitHub repositories to the devops team
resource "github_team_repository" "devops" {
permission = "admin"
# not supported as of 1.1.x :'-(
#for_each = github_repository[*].name
for_each = data.external.github_repos.result
repository = each.key
team_id = github_team.devops.id
lifecycle {
# XXX: doesn't prevent destroy when the entire resource code block is removed!
prevent_destroy = true
}
}