Skip to content

Commit 9946a78

Browse files
authored
Merge pull request #244 from stephanosio/github-zephyrproject-rtos
terraform: Add github-zephyrproject-rtos manifests
2 parents 3734cb8 + f9a46e5 commit 9946a78

28 files changed

+1489
-0
lines changed

terraform/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,8 @@ configuration files for the Zephyr infrastructure components.
3232
* Production Kubernetes cluster for Zephyr infrastructure services.
3333
* Hosted on Hetzner Rancher Server.
3434
* Terraform plan and applies are locally executed with Terraform Cloud state backend.
35+
36+
* github-zephyrproject-rtos
37+
38+
* Defines the GitHub `zephyrproject-rtos` organisation resources.
39+
* Terraform plan and applies are remotely executed on the Terraform Cloud.

terraform/github-zephyrproject-rtos/.terraform.lock.hcl

Lines changed: 66 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# github-zephyrproject-rtos
2+
3+
## Overview
4+
5+
This directory contains the Terraform manifests that define the resources in the
6+
GitHub `zephyrproject-rtos` organisation.
7+
8+
The resources defined in this directory include GitHub members, repositories and
9+
teams.
10+
11+
## Modules
12+
13+
### repository
14+
15+
The `repository` module defines the repository configurations and collaborators
16+
for the managed GitHub repositories in the `zephyrproject-rtos` organisation.
17+
18+
The configurations managed by the `repository` module include:
19+
20+
* Repository name and description
21+
* Features (issues, discussions, projects, wiki)
22+
* Default branch
23+
* Pull request merge methods
24+
* Repository collaborators
25+
* Branch protection rules
26+
* Rulesets
27+
* Actions permissions
28+
29+
In order to synchronise the repository configurations, run the following
30+
command:
31+
32+
```
33+
terraform apply -target=module.repository
34+
```
35+
36+
### team
37+
38+
The `team` module defines the GitHub teams and their members in the
39+
`zephyrproject-rtos` organisation.
40+
41+
In order to synchronise the team configurations, run the following command:
42+
43+
```
44+
terraform apply -taget=module.team
45+
```
46+
47+
Note that the team members who have not accepted the invitation are considered
48+
"not-applied" and will show up as required changes during `terraform apply`.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# HashiCorp Vault Secrets zephyr-secrets Vault
2+
data "hcp_vault_secrets_app" "zephyr_secrets" {
3+
app_name = "zephyr-secrets"
4+
}
5+
6+
# GitHub provider
7+
provider "github" {
8+
owner = "zephyrproject-rtos"
9+
}
10+
11+
# 'team' module defines GitHub teams and their members
12+
module "team" {
13+
source = "./team"
14+
}
15+
16+
# 'repository' module defines GitHub repository configurations and
17+
# collaborators
18+
module "repository" {
19+
source = "./repository"
20+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
locals {
2+
repository_members_path = "repository/repository-members"
3+
repository_members_files = {
4+
for file in fileset(local.repository_members_path, "*.csv") :
5+
trimsuffix(file, ".csv") => csvdecode(file("${local.repository_members_path}/${file}"))
6+
}
7+
global_teams = [
8+
"infrastructure"
9+
]
10+
}
11+
12+
resource "github_repository_collaborators" "members" {
13+
for_each = local.repository_members_files
14+
15+
repository = each.key
16+
17+
dynamic "user" {
18+
for_each = {
19+
for u in local.repository_members_files[each.key] :
20+
u.id => u if u.type == "user"
21+
}
22+
23+
content {
24+
username = user.value.id
25+
permission = user.value.permission
26+
}
27+
}
28+
29+
dynamic "team" {
30+
for_each = {
31+
for t in local.repository_members_files[each.key] :
32+
t.id => t if t.type == "team"
33+
}
34+
35+
content {
36+
team_id = team.value.id
37+
permission = team.value.permission
38+
}
39+
}
40+
41+
dynamic "ignore_team" {
42+
for_each = local.global_teams
43+
44+
content {
45+
team_id = ignore_team.value
46+
}
47+
}
48+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
type,id,permission
2+
team,maintainers,triage
3+
team,release,triage
4+
team,sdk,push
5+
user,nashif,admin
6+
user,stephanosio,admin
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
resource "github_repository" "sdk-ng" {
2+
name = "sdk-ng"
3+
description = "Zephyr SDK (Toolchains, Development Tools)"
4+
5+
has_issues = true
6+
has_discussions = true
7+
has_projects = true
8+
has_wiki = true
9+
has_downloads = true
10+
11+
allow_merge_commit = false
12+
allow_squash_merge = false
13+
allow_rebase_merge = true
14+
allow_auto_merge = false
15+
allow_update_branch = true
16+
}
17+
18+
# Default branch
19+
resource "github_branch_default" "sdk-ng" {
20+
repository = github_repository.sdk-ng.name
21+
branch = github_branch.sdk-ng-main.branch
22+
}
23+
24+
# Actions
25+
resource "github_actions_repository_permissions" "sdk-ng" {
26+
allowed_actions = "all"
27+
repository = github_repository.sdk-ng.name
28+
}
29+
30+
# Branches
31+
resource "github_branch" "sdk-ng-main" {
32+
branch = "main"
33+
repository = github_repository.sdk-ng.name
34+
}
35+
36+
# Branch Protection Rules
37+
resource "github_branch_protection" "sdk-ng-main" {
38+
pattern = "main"
39+
40+
enforce_admins = false
41+
42+
require_conversation_resolution = false
43+
require_signed_commits = false
44+
required_linear_history = true
45+
lock_branch = false
46+
47+
allows_force_pushes = false
48+
allows_deletions = false
49+
50+
required_pull_request_reviews {
51+
required_approving_review_count = 1
52+
dismiss_stale_reviews = false
53+
require_code_owner_reviews = false
54+
require_last_push_approval = false
55+
}
56+
57+
required_status_checks {
58+
strict = false
59+
contexts = ["Test Result"]
60+
}
61+
62+
restrict_pushes {
63+
blocks_creations = true
64+
push_allowances = [
65+
# Only allow users with "Maintain" access level to push.
66+
]
67+
}
68+
69+
repository_id = github_repository.sdk-ng.node_id
70+
}
71+
72+
resource "github_branch_protection" "sdk-ng-vx-branch" {
73+
pattern = "v*-branch"
74+
75+
require_conversation_resolution = false
76+
require_signed_commits = false
77+
required_linear_history = true
78+
lock_branch = false
79+
enforce_admins = false
80+
81+
allows_force_pushes = false
82+
allows_deletions = false
83+
84+
required_pull_request_reviews {
85+
required_approving_review_count = 1
86+
dismiss_stale_reviews = false
87+
require_code_owner_reviews = false
88+
require_last_push_approval = false
89+
}
90+
91+
required_status_checks {
92+
strict = false
93+
contexts = ["Test Result"]
94+
}
95+
96+
restrict_pushes {
97+
blocks_creations = true
98+
push_allowances = [
99+
# Only allow users with "Maintain" access level to push.
100+
]
101+
}
102+
103+
repository_id = github_repository.sdk-ng.node_id
104+
}
105+
106+
# Rulesets
107+
resource "github_repository_ruleset" "sdk-ng-block-release-tag-modification" {
108+
name = "Block release tag modification"
109+
target = "tag"
110+
enforcement = "active"
111+
112+
conditions {
113+
ref_name {
114+
include = ["refs/tags/v*"]
115+
exclude = []
116+
}
117+
}
118+
119+
rules {
120+
# Restrict creations
121+
creation = false
122+
# Restrict updates
123+
update = true
124+
# Restrict deletions
125+
deletion = true
126+
# Require linear history
127+
required_linear_history = false
128+
# Require signed commits
129+
required_signatures = false
130+
# Block force pushes
131+
non_fast_forward = true
132+
}
133+
134+
repository = github_repository.sdk-ng.name
135+
}
136+
137+
resource "github_repository_ruleset" "sdk-ng-restrict-release-tag-creation" {
138+
name = "Restrict release tag creation"
139+
target = "tag"
140+
enforcement = "active"
141+
142+
conditions {
143+
ref_name {
144+
include = ["refs/tags/v*"]
145+
exclude = []
146+
}
147+
}
148+
149+
rules {
150+
# Restrict creations
151+
creation = true
152+
# Restrict updates
153+
update = false
154+
# Restrict deletions
155+
deletion = false
156+
# Require linear history
157+
required_linear_history = false
158+
# Require signed commits
159+
required_signatures = false
160+
# Block force pushes
161+
non_fast_forward = false
162+
}
163+
164+
bypass_actors {
165+
actor_type = "RepositoryRole"
166+
actor_id = "2" # Maintain
167+
bypass_mode = "always"
168+
}
169+
170+
bypass_actors {
171+
actor_type = "RepositoryRole"
172+
actor_id = "5" # Repository admin
173+
bypass_mode = "always"
174+
}
175+
176+
repository = github_repository.sdk-ng.name
177+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 0.14.0"
3+
4+
required_providers {
5+
github = {
6+
source = "integrations/github"
7+
version = "~> 6.0"
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)