Skip to content

Commit 1bd7586

Browse files
authored
Merge pull request #8 from Homebrew/feat/github/creat_all_teams
feat: add all teams as an import
2 parents 01be30a + a189d99 commit 1bd7586

12 files changed

+118
-62
lines changed

.tfvars

+3-3
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ teams = {
102102
"timsutton",
103103
"woodruffw",
104104
],
105-
formulae-web = [
105+
formulae_brew_sh = [
106106
"EricFromCanada",
107107
"MikeMcQuaid",
108108
"Rylan12",
@@ -130,10 +130,10 @@ teams = {
130130
"jacobbednarz",
131131
"MikeMcQuaid",
132132
],
133-
linux-fonts = [
133+
homebrew-linux-fonts = [
134134
"tani",
135135
],
136-
pip = [
136+
brew-pip-audit = [
137137
"alex",
138138
"woodruffw",
139139
],

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# terraform-user-management
1+
# homebrew-user-management
22

3-
User management for the Homebrew organisation using Terraform
3+
User management for the Homebrew organisation using OpenTofu
44

55
## Requirements
66

@@ -18,3 +18,4 @@ User management for the Homebrew organisation using Terraform
1818

1919
- Google workspace management for brew.sh
2020
- Google Cloud manangement for self-hosted workers
21+
- Add DNSSimple

github/groups.tf

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
locals {
2+
teams = concat(
3+
[for team in keys(var.teams) : team if !contains(["bots", "taps"], team)],
4+
keys(tomap(var.teams.maintainers)),
5+
keys(tomap(var.teams.taps))
6+
)
7+
}
8+
9+
resource "github_team" "main" {
10+
name = each.key
11+
privacy = "closed"
12+
13+
for_each = { for team in keys(var.teams) : team => team if !contains(["bots", "taps"], team) }
14+
15+
lifecycle {
16+
ignore_changes = [description]
17+
}
18+
}
19+
20+
resource "github_team" "maintainers" {
21+
name = replace(each.key, "_", ".")
22+
privacy = "closed"
23+
parent_team_id = github_team.main["maintainers"].id
24+
25+
for_each = { for team in keys(var.teams.maintainers) : team => team }
26+
27+
lifecycle {
28+
ignore_changes = [description]
29+
}
30+
}
31+
32+
resource "github_team" "taps" {
33+
name = replace(each.key, "_", ".")
34+
privacy = "closed"
35+
36+
for_each = { for team in keys(var.teams.taps) : team => team }
37+
38+
lifecycle {
39+
ignore_changes = [description]
40+
}
41+
}
42+
43+
resource "github_team_membership" "ops_membership" {
44+
for_each = toset(var.teams.maintainers.ops)
45+
team_id = github_team.maintainers["ops"].id
46+
username = each.key
47+
role = contains(var.admins, each.key) ? "maintainer" : "member"
48+
}
49+
50+
resource "github_team_membership" "plc_membership" {
51+
for_each = toset(var.teams.plc)
52+
team_id = github_team.main["plc"].id
53+
username = each.key
54+
role = contains(var.admins, each.key) ? "maintainer" : "member"
55+
}
56+
57+
resource "github_team_membership" "tsc_membership" {
58+
for_each = toset(var.teams.maintainers.tsc)
59+
team_id = github_team.maintainers["tsc"].id
60+
username = each.key
61+
role = contains(var.admins, each.key) ? "maintainer" : "member"
62+
}

github/main_groups.tf

-4
This file was deleted.

github/membership.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ locals {
1111
}
1212

1313
resource "github_membership" "general" {
14-
for_each = toset([ for member in local.members: member if !contains(var.unmanagable_members, member)])
14+
for_each = toset([for member in local.members : member if !contains(var.unmanagable_members, member)])
1515
username = each.key
1616
role = contains(var.admins, each.key) ? "admin" : "member"
1717
}

github/ops.tf

-10
This file was deleted.

github/plc.tf

-10
This file was deleted.

github/tsc.tf

-10
This file was deleted.

github/vars.tf

+11-11
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ variable "teams" {
55
bots = list(string)
66
members = list(string)
77
maintainers = object({
8-
cask = list(string)
9-
brew = list(string)
10-
core = list(string)
11-
tsc = list(string)
12-
ops = list(string)
13-
formulae-web = list(string)
14-
ci-orchestrator = list(string)
8+
cask = list(string)
9+
brew = list(string)
10+
core = list(string)
11+
tsc = list(string)
12+
ops = list(string)
13+
formulae_brew_sh = list(string)
14+
ci-orchestrator = list(string)
1515
})
1616
taps = object({
17-
bundle = list(string)
18-
pip = list(string)
19-
linux-fonts = list(string)
20-
services = list(string)
17+
bundle = list(string)
18+
brew-pip-audit = list(string)
19+
homebrew-linux-fonts = list(string)
20+
services = list(string)
2121
})
2222
})
2323
}

import.tf

+18
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,22 @@ import {
3232
for_each = toset([for member in local.members : member if !contains(local.unmanagable_members, member)])
3333
to = module.github.github_membership.general[each.key]
3434
id = "Homebrew:${each.key}"
35+
}
36+
37+
import {
38+
for_each = { for team in keys(var.teams) : team => team if !contains(["bots", "taps"], team) }
39+
to = module.github.github_team.main[each.key]
40+
id = each.key
41+
}
42+
43+
import {
44+
for_each = { for team in keys(var.teams.taps) : team => team }
45+
to = module.github.github_team.taps[each.key]
46+
id = replace(each.key, "_", "-")
47+
}
48+
49+
import {
50+
for_each = { for team in keys(var.teams.maintainers) : team => team }
51+
to = module.github.github_team.maintainers[each.key]
52+
id = replace(each.key, "_", "-")
3553
}

main.tf

+9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ terraform {
66
}
77
}
88

9+
terraform {
10+
required_providers {
11+
github = {
12+
source = "integrations/github"
13+
version = "~> 6.0"
14+
}
15+
}
16+
}
17+
918
locals {
1019
# these people can't have their membership managed by OpenTofu becuase they are Billing Managers in GitHub
1120
unmanagable_members = ["p-linnane", "issyl0", "colindean", "MikeMcQuaid", "BrewSponsorsBot"]

vars.tf

+11-11
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ variable "teams" {
55
bots = list(string)
66
members = list(string)
77
maintainers = object({
8-
cask = list(string)
9-
brew = list(string)
10-
core = list(string)
11-
tsc = list(string)
12-
ops = list(string)
13-
formulae-web = list(string)
14-
ci-orchestrator = list(string)
8+
cask = list(string)
9+
brew = list(string)
10+
core = list(string)
11+
tsc = list(string)
12+
ops = list(string)
13+
formulae_brew_sh = list(string)
14+
ci-orchestrator = list(string)
1515
})
1616
taps = object({
17-
bundle = list(string)
18-
pip = list(string)
19-
linux-fonts = list(string)
20-
services = list(string)
17+
bundle = list(string)
18+
brew-pip-audit = list(string)
19+
homebrew-linux-fonts = list(string)
20+
services = list(string)
2121
})
2222
})
2323
}

0 commit comments

Comments
 (0)