locals { avatars_dir = var.avatars_dir == "" ? "${path.root}/images" : var.avatars_dir allowed_avatar_types_json = var.allowed_avatar_types_json == "" ? "${path.root}/data/allowed_avatar_project_types.json" : var.allowed_avatar_types_json allowed_avatar_types = jsondecode(file("${local.allowed_avatar_types_json}")) allowed_project_types_json = var.allowed_avatar_types_json == "" ? "${path.root}/data/allowed_project_types.json" : var.allowed_project_types_json allowed_project_types = jsondecode(try(file("${local.allowed_project_types_json}"), null) == null ? file("${path.module}/data/allowed_project_types.json") : file(local.allowed_project_types_json)) # Define the allowed project types as a map avatar_project = local.allowed_project_types[var.project_type].avatar == "" ? null : "${local.avatars_dir}/${local.allowed_project_types[var.project_type].avatar}.png" avatar_path = var.avatar == "" ? local.avatar_project : "${local.avatars_dir}/${var.avatar}.png" avatar = try(file("${local.avatar_path}"), null) == null ? "${local.avatar_path}" : null token_scope_group_ids = [for g in values(data.gitlab_group.token_scope_groups) : g.id] token_scope_project_ids = [for p in values(data.gitlab_project.token_scope_projects) : p.id] merged_scope_variables = merge( local.allowed_project_types[var.project_type].scoped_variables, var.scoped_variables ) merged_environments = merge( local.allowed_project_types[var.project_type].environments, var.environments ) merged_project_variables = merge( local.allowed_project_types[var.project_type].variables, { PROJECT_TYPE = { description = "Project Type" value = var.project_type protected = "false" masked = "false" }, IS_ENABLED_CHECKMARX = { description = "Enabled CheckMarx scan" value = var.is_enabled_checkmarx == true ? "true" : "false" protected = "false" masked = "false" }, IS_ENABLED_SONARQUBE = { description = "Enabled SonarQube scan" value = var.is_enabled_sonarqube == true ? "true" : "false" protected = "false" masked = "false" }, SIB_APLIKACJA = { description = "[UPW] ID Aplikacji zasobów SIB" value = var.sib_aplikacja protected = "false" masked = "false" } }, var.ci_variables ) scoped_variable_map = { for pair in flatten([ for var_name, cfg in local.merged_scope_variables : [ for env_scope, v in cfg.values : { id = "${var_name}::${env_scope}" data = { key = var_name environment_scope = env_scope != "" ? env_scope : "*" value = v protected = cfg.protected masked = cfg.masked description = cfg.description } } ] ]) : pair.id => pair.data } }