Skip to content

Commit e250a93

Browse files
committed
refs sparkfabrik-innovation-team/board#3833: Refactor configuration and documentation for GitLab Agent module to simplify root group behavior and enhance variable management
1 parent 434c27e commit e250a93

File tree

4 files changed

+358
-16
lines changed

4 files changed

+358
-16
lines changed

files/config.yaml.tftpl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ user_access:
1212
%{~ else ~}
1313
%{~ if length(groups_to_enable) > 0 || length(projects_to_enable) > 0 ~}
1414
ci_access:
15-
%{~ if length(groups_to_enable) > 0 ~}
15+
%{~ if length(groups_to_enable) > 0 ~}
1616
groups:
17-
%{~ for group in groups_to_enable ~}
17+
%{~ for group in groups_to_enable ~}
1818
- id: ${group}
19-
%{~ endfor ~}
20-
%{~ endif ~}
21-
%{~ if length(projects_to_enable) > 0 ~}
19+
%{~ endfor ~}
20+
%{~ endif ~}
21+
%{~ if length(projects_to_enable) > 0 ~}
2222
projects:
23-
%{~ for project in projects_to_enable ~}
23+
%{~ for project in projects_to_enable ~}
2424
- id: ${project}
25-
%{~ endfor ~}
26-
%{~ endif ~}
25+
%{~ endfor ~}
26+
%{~ endif ~}
2727
%{~ endif ~}
2828
%{~ endif ~}
2929

30-
%{~ if trimspace(gitlab_agent_append_to_config_file) != "" ~}
30+
%{~ if trimspace(gitlab_agent_append_to_config_file) != "" }
3131
${gitlab_agent_append_to_config_file}
3232
%{~ endif ~}

main.tf

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ locals {
2121

2222
# Determine the parent group of the project
2323
project_path_parts = split("/", var.gitlab_project_path_with_namespace)
24-
parent_group_path = length(local.project_path_parts) > 1 ? join("/", slice(local.project_path_parts, 0, length(local.project_path_parts) - 1)) : local.project_root_namespace
24+
parent_group_path = length(local.project_path_parts) > 1 ? join("/", slice(local.project_path_parts, 0, length(local.project_path_parts) - 1)) : ""
2525

2626
# Determine if we are in auto-parent mode
2727
auto_detect_parent = !var.operate_at_root_group_level && length(concat(var.groups_enabled, var.projects_enabled)) == 0
2828

2929
# Final list of groups to enable
30-
groups_to_enable = var.operate_at_root_group_level ? [local.project_root_namespace] : (
30+
groups_to_enable = var.operate_at_root_group_level ? [] : (
3131
local.auto_detect_parent ? [local.parent_group_path] : var.groups_enabled
3232
)
3333

@@ -39,11 +39,11 @@ locals {
3939
# Gitlab Agent configuration file
4040
final_configuration_file_content = var.gitlab_agent_custom_config_file_content != "" ? var.gitlab_agent_custom_config_file_content : templatefile("${path.module}/files/config.yaml.tftpl", {
4141
operate_at_root_group_level = var.operate_at_root_group_level
42+
gitlab_agent_grant_user_access_to_root_namespace = var.gitlab_agent_grant_user_access_to_root_namespace
4243
root_namespace = data.gitlab_group.root_namespace.path
4344
groups_to_enable = local.groups_to_enable
4445
projects_to_enable = local.projects_to_enable
4546
gitlab_agent_append_to_config_file = var.gitlab_agent_append_to_config_file
46-
gitlab_agent_grant_user_access_to_root_namespace = var.gitlab_agent_grant_user_access_to_root_namespace
4747
})
4848

4949
# Gitlab Agent CI/CD variables
@@ -141,7 +141,7 @@ resource "gitlab_group_variable" "root_namespace" {
141141
resource "gitlab_group_variable" "enabled_groups" {
142142
for_each = !var.operate_at_root_group_level && length(local.groups_to_enable) > 0 ? {
143143
for pair in setproduct(keys(local.gitlab_agent_kubernetes_context_variables), local.groups_to_enable) :
144-
"${pair[1]}_${pair[0]}" => {
144+
"${pair[1]}__${pair[0]}" => {
145145
group_path = pair[1]
146146
key = pair[0]
147147
value = local.gitlab_agent_kubernetes_context_variables[pair[0]]
@@ -153,14 +153,13 @@ resource "gitlab_group_variable" "enabled_groups" {
153153
value = each.value.value
154154
protected = false
155155
masked = false
156-
157156
}
158157

159158
# Variables for specific projects (when operate_at_root_group_level is false)
160159
resource "gitlab_project_variable" "enabled_projects" {
161160
for_each = !var.operate_at_root_group_level && length(local.projects_to_enable) > 0 ? {
162161
for pair in setproduct(keys(local.gitlab_agent_kubernetes_context_variables), local.projects_to_enable) :
163-
"${pair[1]}_${pair[0]}" => {
162+
"${pair[1]}__${pair[0]}" => {
164163
project_path = pair[1]
165164
key = pair[0]
166165
value = local.gitlab_agent_kubernetes_context_variables[pair[0]]
@@ -172,7 +171,6 @@ resource "gitlab_project_variable" "enabled_projects" {
172171
value = each.value.value
173172
protected = false
174173
masked = false
175-
176174
}
177175

178176
# Kubernetes resources

0 commit comments

Comments
 (0)