forked from mineiros-io/terraform-github-organization
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
56 lines (43 loc) · 1.52 KB
/
main.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
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# MANAGE A GITHUB ORGANIZATION
# - manage memberships ( admins and members )
# - manage blocked users
# - manage projects
# - create the team "all" that contains every member of the organization
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
locals {
admins = { for i in var.admins : lower(i) => "admin" }
members = { for i in var.members : lower(i) => "member" }
memberships = merge(local.admins, local.members)
}
resource "github_membership" "membership" {
for_each = local.memberships
username = each.key
role = each.value
}
resource "github_organization_block" "blocked_user" {
for_each = var.blocked_users
username = each.value
}
locals {
projects = { for p in var.projects : lookup(p, "id", lower(p.name)) => merge({
body = null
}, p) }
}
resource "github_organization_project" "project" {
for_each = local.projects
name = each.value.name
body = each.value.body
}
resource "github_team" "all" {
count = var.all_members_team_name != null ? 1 : 0
name = var.all_members_team_name
description = "This teams contains all members of our organization."
privacy = var.all_members_team_visibility
}
resource "github_team_membership" "all" {
for_each = var.all_members_team_name != null ? local.memberships : {}
team_id = github_team.all[0].id
username = each.key
role = "member"
}