From 7bd65508f1224dfb3ed3ee29e338f0cfc53df3f7 Mon Sep 17 00:00:00 2001 From: Anton <171003811+Anton0C@users.noreply.github.com> Date: Fri, 18 Jul 2025 08:57:19 +0200 Subject: [PATCH 1/2] Add gitlab_projects_external variable --- variables.tf | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/variables.tf b/variables.tf index a6c9c3c..5b84cc1 100644 --- a/variables.tf +++ b/variables.tf @@ -11,6 +11,11 @@ variable "gitlab_projects" { type = any } +variable "gitlab_projects_external" { + description = "List of GitLab projects managed outside of this module." + type = any +} + variable "tier" { type = string description = "Gitlab tier" From 6adf83a215c564cffcc2bad15ecf14df56499d51 Mon Sep 17 00:00:00 2001 From: Anton <171003811+Anton0C@users.noreply.github.com> Date: Fri, 18 Jul 2025 08:59:06 +0200 Subject: [PATCH 2/2] allow to use external projects tokens to authenticate requests --- main.tf | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 79edd61..6179996 100644 --- a/main.tf +++ b/main.tf @@ -870,6 +870,12 @@ resource "gitlab_project_issue" "this" { weight = lookup(each.value.issue, "weight", null) } +# Some projects are managed outside of this module, collect them here +data "gitlab_project" "external" { + for_each = { for p in var.gitlab_projects_external : p => p } + path_with_namespace = each.key +} + resource "gitlab_project_job_token_scope" "this" { for_each = merge([ for project in var.gitlab_projects : { @@ -884,7 +890,11 @@ resource "gitlab_project_job_token_scope" "this" { # Use the correct project ID project = gitlab_project.this["${each.value.project_namespace}/${each.value.project_name}"].id - target_project_id = gitlab_project.this[each.value.job_token_scope.target_project_id].id + target_project_id = ( + contains(keys(gitlab_project.this), each.value.job_token_scope.target_project_id) ? + gitlab_project.this[each.value.job_token_scope.target_project_id].id : + data.gitlab_project.external[each.value.job_token_scope.target_project_id].id + ) } resource "gitlab_project_label" "this" {