From 6da075f51c2482a76e0f6e52f19ec13b76c6fb45 Mon Sep 17 00:00:00 2001 From: FabrizioCafolla Date: Mon, 13 Oct 2025 17:13:18 +0200 Subject: [PATCH 1/5] feat: remove autoassign current user by default --- CHANGELOG.md | 8 ++++++++ README.md | 4 ++-- main.tf | 4 +--- variables.tf | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64d7c64..335b215 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,14 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +## [1.2.0] - 2025-10-13 + +[Compare with previous version](https://github.com/sparkfabrik/terraform-gitlab-kubernetes-gitlab-agent/compare/1.1.0...1.2.0) + +### Added + +- feat: remove autoassign current user by default + ## [1.1.0] - 2025-10-08 [Compare with previous version](https://github.com/sparkfabrik/terraform-gitlab-kubernetes-gitlab-agent/compare/1.0.0...1.1.0) diff --git a/README.md b/README.md index bfb131c..eefebd9 100644 --- a/README.md +++ b/README.md @@ -77,11 +77,11 @@ provider "gitlab" { ## GitLab Agents user membership -The current user used by the provider is automatically added as `maintainer` to the "GitLab Agents" project. If you don't want this behavior, just set the variable `var.autoassign_current_user_as_maintainer` to `false`. +The current user used by the provider must be added as `maintainer` to the "GitLab Agents" project. This behavior by default is disable, just set the variable `var.autoassign_current_user_as_maintainer` to `true` if you want enable. Adding the user as `maintainer` to the newly created project ensures they have the permissions to commit and push to it. -**ATTENTION:** If the current user is already added to the project but with a different role than `maintainer`, the apply will fail saying that a membership already exists +**ATTENTION:** If the current user is already added to the project the apply will fail saying that a membership already exists ## Providers diff --git a/main.tf b/main.tf index 70f7d4e..c738ef7 100644 --- a/main.tf +++ b/main.tf @@ -51,8 +51,6 @@ locals { (var.gitlab_agent_variable_name_agent_id) : gitlab_cluster_agent.this.name, (var.gitlab_agent_variable_name_agent_project) : local.project_path_with_namespace, } - - current_user_is_maintainer_of_project = length([for member in data.gitlab_project_membership.this.members : member if member.name == data.gitlab_current_user.this.name && member.access_level == "maintainer"]) > 0 } # Gitlab resources @@ -99,7 +97,7 @@ resource "gitlab_project" "project" { } resource "gitlab_project_membership" "project" { - count = var.autoassign_current_user_as_maintainer && !local.current_user_is_maintainer_of_project ? 1 : 0 + count = var.autoassign_current_user_as_maintainer ? 1 : 0 project = local.project_id user_id = data.gitlab_current_user.this.id access_level = "maintainer" diff --git a/variables.tf b/variables.tf index f755e21..f25e8d8 100644 --- a/variables.tf +++ b/variables.tf @@ -159,5 +159,5 @@ variable "create_default_pod_anti_affinity" { variable "autoassign_current_user_as_maintainer" { description = "Automatically assign the current GitLab user (from the GitLab provider) as a maintainer of the created project. This is useful to ensure that the user has rights to commit and push the GitLab Agent configuration file." type = bool - default = true + default = false } From 9a62d621cd342ef1b5f3beac3d3a5e1b3913e9ea Mon Sep 17 00:00:00 2001 From: Fabrizio Cafolla Date: Mon, 13 Oct 2025 17:18:56 +0200 Subject: [PATCH 2/5] Update CHANGELOG.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 335b215..536b704 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ### Added -- feat: remove autoassign current user by default +- feat: disable autoassign current user by default ## [1.1.0] - 2025-10-08 From 14d3028d2878394c64c0e722b4df2ef231263a0d Mon Sep 17 00:00:00 2001 From: Fabrizio Cafolla Date: Mon, 13 Oct 2025 17:19:13 +0200 Subject: [PATCH 3/5] Update README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index eefebd9..0c631dd 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ provider "gitlab" { ## GitLab Agents user membership -The current user used by the provider must be added as `maintainer` to the "GitLab Agents" project. This behavior by default is disable, just set the variable `var.autoassign_current_user_as_maintainer` to `true` if you want enable. +The current user used by the provider must be added as `maintainer` to the "GitLab Agents" project. By default, this behavior is disabled; just set the variable `var.autoassign_current_user_as_maintainer` to `true` if you want to enable it. Adding the user as `maintainer` to the newly created project ensures they have the permissions to commit and push to it. From 951aef6c6873c66412150225c86470c767f1b7bc Mon Sep 17 00:00:00 2001 From: FabrizioCafolla Date: Mon, 13 Oct 2025 17:33:51 +0200 Subject: [PATCH 4/5] fix --- main.tf | 2 +- variables.tf | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/main.tf b/main.tf index c738ef7..3c5bc44 100644 --- a/main.tf +++ b/main.tf @@ -97,7 +97,7 @@ resource "gitlab_project" "project" { } resource "gitlab_project_membership" "project" { - count = var.autoassign_current_user_as_maintainer ? 1 : 0 + count = var.assign_current_user_as_maintainer ? 1 : 0 project = local.project_id user_id = data.gitlab_current_user.this.id access_level = "maintainer" diff --git a/variables.tf b/variables.tf index f25e8d8..8057aef 100644 --- a/variables.tf +++ b/variables.tf @@ -156,8 +156,8 @@ variable "create_default_pod_anti_affinity" { default = true } -variable "autoassign_current_user_as_maintainer" { - description = "Automatically assign the current GitLab user (from the GitLab provider) as a maintainer of the created project. This is useful to ensure that the user has rights to commit and push the GitLab Agent configuration file." +variable "assign_current_user_as_maintainer" { + description = "Assign the current GitLab user (from the GitLab provider) as a maintainer of the created project. This is useful to ensure that the user has rights to commit and push the GitLab Agent configuration file." type = bool default = false } From 2eb0de791b65e832d0028308aa56a4f611cfabb5 Mon Sep 17 00:00:00 2001 From: FabrizioCafolla Date: Mon, 13 Oct 2025 17:36:08 +0200 Subject: [PATCH 5/5] update --- main.tf | 5 ----- 1 file changed, 5 deletions(-) diff --git a/main.tf b/main.tf index 3c5bc44..d499eb9 100644 --- a/main.tf +++ b/main.tf @@ -85,11 +85,6 @@ data "gitlab_project" "enabled_projects" { path_with_namespace = each.value } -# Data source to get all the memberships for the project -data "gitlab_project_membership" "this" { - project_id = local.project_id -} - resource "gitlab_project" "project" { count = local.use_existing_project == 0 ? 1 : 0 name = var.gitlab_project_name