Skip to content

Commit 94921be

Browse files
committed
Add secrets sync for private repositories
1 parent 7f37d62 commit 94921be

5 files changed

Lines changed: 68 additions & 0 deletions

File tree

modules/github/secret_sync/main.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module "gl_api_token" {
2+
source = "./synced_secret"
3+
4+
gitlab_secrets_manager_key = "GITHUB_GL_API_TOKEN"
5+
github_secret_key = "GL_API_TOKEN"
6+
}
7+
8+
module "gl_runner_token" {
9+
source = "./synced_secret"
10+
11+
gitlab_secrets_manager_key = "GITHUB_GL_RUNNER_TOKEN"
12+
github_secret_key = "GL_RUNNER_TOKEN"
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
terraform {
2+
required_providers {
3+
github = {
4+
source = "integrations/github"
5+
version = "6.12.1"
6+
}
7+
gitlab = {
8+
source = "gitlabhq/gitlab"
9+
version = "18.11.0"
10+
}
11+
}
12+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
data "gitlab_project_variable" "secret" {
2+
project = "code0-tech/secret-manager"
3+
key = var.gitlab_secrets_manager_key
4+
}
5+
6+
data "github_repositories" "public" {
7+
query = "org:code0-tech props.secret-sync:${var.github_secret_key} visibility:public"
8+
include_repo_id = true
9+
}
10+
11+
data "github_repositories" "private" {
12+
query = "org:code0-tech props.secret-sync:${var.github_secret_key} visibility:private"
13+
}
14+
15+
resource "github_actions_organization_secret" "secret" {
16+
secret_name = var.github_secret_key
17+
visibility = "selected"
18+
value = data.gitlab_project_variable.secret.value
19+
}
20+
21+
resource "github_actions_organization_secret_repositories" "public" {
22+
secret_name = github_actions_organization_secret.secret.secret_name
23+
selected_repository_ids = data.github_repositories.public.repo_ids
24+
}
25+
26+
resource "github_actions_secret" "secret" {
27+
for_each = toset(data.github_repositories.private.names)
28+
29+
repository = each.value
30+
secret_name = var.github_secret_key
31+
value = data.gitlab_project_variable.secret.value
32+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
variable "gitlab_secrets_manager_key" {
2+
type = string
3+
}
4+
5+
variable "github_secret_key" {
6+
type = string
7+
}

system/github/main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ module "licenses" {
3838
source = "../../modules/github/license_files"
3939
}
4040

41+
module "secret_sync" {
42+
source = "../../modules/github/secret_sync"
43+
}
44+
4145
data "gitlab_project_variable" "github_public_discord_webhook_url" {
4246
project = "code0-tech/secret-manager"
4347
key = "GITHUB_PUBLIC_DISCORD_WEBHOOK_URL"

0 commit comments

Comments
 (0)