Skip to content

Commit cc56d18

Browse files
authored
Merge pull request #1 from github-as-code/import
Bring in the modules for github_repo and github_team
2 parents c8ec8f3 + eafe6c5 commit cc56d18

File tree

5 files changed

+114
-0
lines changed

5 files changed

+114
-0
lines changed

modules/github_repo/main.tf

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
resource "github_repository" "repository" {
2+
name = "${var.repository_name}"
3+
4+
# Our repos should always be public. If you need to make something secret you better have a good reason
5+
private = false
6+
7+
# We auto init so that github_branch_protection works
8+
auto_init = true
9+
}
10+
11+
resource "github_branch_protection" "branch" {
12+
# As part of our SDLC we require that master branch can not be merged to unless...
13+
14+
repository = "${var.repository_name}"
15+
branch = "master"
16+
17+
# enforce protection on admins
18+
enforce_admins = true
19+
20+
# all status checks pass
21+
required_status_checks {
22+
strict = true
23+
contexts = []
24+
}
25+
26+
# Tune review requirements
27+
required_pull_request_reviews {
28+
dismiss_stale_reviews = true
29+
}
30+
31+
depends_on = ["github_repository.repository"]
32+
}
33+
34+
resource "github_team_repository" "admin_teams" {
35+
count = "${var.admin_teams_count}"
36+
team_id = "${element(var.admin_teams, count.index)}"
37+
repository = "${github_repository.repository.id}"
38+
permission = "admin"
39+
}
40+
41+
resource "github_team_repository" "pull_teams" {
42+
count = "${var.pull_teams_count}"
43+
team_id = "${element(var.pull_teams, count.index)}"
44+
repository = "${github_repository.repository.id}"
45+
permission = "pull"
46+
}

modules/github_repo/vars.tf

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
variable "repository_name" {
2+
description = "The name of the repository that is to be created."
3+
}
4+
5+
variable "admin_teams_count" {
6+
description = "Required count variable representing number of teams passed to the admin_teams variable"
7+
default = 0
8+
}
9+
10+
variable "admin_teams" {
11+
description = "Admin team members"
12+
type = "list"
13+
default = []
14+
}
15+
16+
variable "pull_teams_count" {
17+
description = "Required count variable representing number of teams passed to the pull_teams variable"
18+
default = 0
19+
}
20+
21+
variable "pull_teams" {
22+
description = "Pull team members"
23+
type = "list"
24+
default = []
25+
}

modules/github_team/main.tf

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
resource "github_team" "team_name" {
2+
name = "${var.team_name}"
3+
description = "${var.team_description}"
4+
privacy = "${var.privacy}"
5+
}
6+
7+
resource "github_team_membership" "member" {
8+
count = "${length(var.members)}"
9+
team_id = "${github_team.team_name.id}"
10+
username = "${element(var.members, count.index)}"
11+
role = "${replace(var.role, "/admin/", "maintainer")}"
12+
}
13+
14+
resource "github_membership" "member" {
15+
count = "${length(var.members)}"
16+
username = "${element(var.members, count.index)}"
17+
role = "${replace(var.role, "/maintainer/", "member")}"
18+
}

modules/github_team/outputs.tf

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
output "team_id" {
2+
value = "${github_team.team_name.id}"
3+
}

modules/github_team/vars.tf

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
variable "team_name" {
2+
description = "Name of the team."
3+
}
4+
5+
variable "team_description" {
6+
description = "Team description."
7+
}
8+
9+
variable "privacy" {
10+
description = "Privacy level of the team."
11+
default = "closed"
12+
}
13+
14+
variable "members" {
15+
description = "List of members of the team."
16+
type = "list"
17+
}
18+
19+
variable "role" {
20+
description = "Role time of the members"
21+
default = "member"
22+
}

0 commit comments

Comments
 (0)