diff --git a/modules/gitlab/runner_support_webhook/main.tf b/modules/gitlab/runner_support_webhook/main.tf new file mode 100644 index 00000000..168a6d7b --- /dev/null +++ b/modules/gitlab/runner_support_webhook/main.tf @@ -0,0 +1,37 @@ +terraform { + required_providers { + gitlab = { + source = "gitlabhq/gitlab" + version = "18.5.0" + } + } +} + +data "gitlab_project_variable" "runner_support_token" { + project = "code0-tech/secret-manager" + key = "GITHUB_RUNNER_SUPPORT_TOKEN" +} + +resource "gitlab_project_hook" "runner_support" { + project = var.project + url = "https://api.github.com/repos/code0-tech/monoceros/actions/workflows/${var.runner_type}.yml/dispatches" + + push_events = false + pipeline_events = true + + custom_webhook_template = jsonencode( + { + "ref": "main", + "inputs": { + "project": "{{project.id}}" + } + } + ) + + custom_headers = [ + { + key = "Authorization" + value = "Bearer ${data.gitlab_project_variable.runner_support_token.value}" + } + ] +} diff --git a/modules/gitlab/runner_support_webhook/variables.tf b/modules/gitlab/runner_support_webhook/variables.tf new file mode 100644 index 00000000..a1f29a80 --- /dev/null +++ b/modules/gitlab/runner_support_webhook/variables.tf @@ -0,0 +1,7 @@ +variable "runner_type" { + type = string +} + +variable "project" { + type = string +} diff --git a/system/gitlab/main.tf b/system/gitlab/main.tf index d978e626..42f48032 100644 --- a/system/gitlab/main.tf +++ b/system/gitlab/main.tf @@ -7,37 +7,36 @@ terraform { } } -data "gitlab_project_variable" "runner_support_token" { - project = "code0-tech/secret-manager" - key = "GITHUB_RUNNER_SUPPORT_TOKEN" +module "runner_support_main" { + source = "../../modules/gitlab/runner_support_webhook" + + for_each = toset([ + "code0-tech/development/sagittarius", + "code0-tech/development/reticulum", + ]) + + project = each.value + runner_type = "runner-support" } -resource "gitlab_project_hook" "runner_support" { - for_each = { - "code0-tech/development/sagittarius": "runner-support", - "code0-tech/development/reticulum": "runner-support", - "code0-tech/infrastructure/pyxis": "runner-support-infra", - } +module "runner_support_infra" { + source = "../../modules/gitlab/runner_support_webhook" - project = each.key - url = "https://api.github.com/repos/code0-tech/monoceros/actions/workflows/${each.value}.yml/dispatches" + for_each = toset([ + "code0-tech/infrastructure/pyxis" + ]) - push_events = false - pipeline_events = true + project = each.value + runner_type = "runner-support-infra" +} - custom_webhook_template = jsonencode( - { - "ref": "main", - "inputs": { - "project": "{{project.id}}" - } - } - ) +module "runner_support_arm" { + source = "../../modules/gitlab/runner_support_webhook" - custom_headers = [ - { - key = "Authorization" - value = "Bearer ${data.gitlab_project_variable.runner_support_token.value}" - } - ] + for_each = toset([ + "code0-tech/development/reticulum" + ]) + + project = each.value + runner_type = "runner-support-arm" }