@@ -870,6 +870,21 @@ resource "gitlab_project_issue" "this" {
870870 weight = lookup (each. value . issue , " weight" , null )
871871}
872872
873+ locals {
874+ # Extract projects for job_token_scopes
875+ all_gitlab_projects = flatten ([
876+ for project in var . gitlab_projects : [
877+ for scope in lookup (project. settings , " job_token_scopes" , []) : scope . target_project_id
878+ ] if lookup (project. settings , " job_token_scopes" , []) != []
879+ ])
880+ }
881+
882+ # Some projects are managed outside of this module, collect them here
883+ data "gitlab_project" "external_managed" {
884+ for_each = toset (local. all_gitlab_projects )
885+ path_with_namespace = each. value
886+ }
887+
873888resource "gitlab_project_job_token_scope" "this" {
874889 for_each = merge ([
875890 for project in var . gitlab_projects : {
@@ -884,7 +899,11 @@ resource "gitlab_project_job_token_scope" "this" {
884899
885900 # Use the correct project ID
886901 project = gitlab_project. this [" ${ each . value . project_namespace } /${ each . value . project_name } " ]. id
887- target_project_id = gitlab_project. this [each . value . job_token_scope . target_project_id ]. id
902+ target_project_id = (
903+ contains (keys (gitlab_project. this ), each. value . job_token_scope . target_project_id ) ?
904+ gitlab_project. this [each . value . job_token_scope . target_project_id ]. id :
905+ data. gitlab_project . external_managed [each . value . job_token_scope . target_project_id ]. id
906+ )
888907}
889908
890909resource "gitlab_project_label" "this" {
0 commit comments