Skip to content

Commit e63181a

Browse files
feat: disable autoassign current user by default (#25)
1 parent 7c5c0b1 commit e63181a

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
88

99
## [Unreleased]
1010

11+
## [1.2.0] - 2025-10-13
12+
13+
[Compare with previous version](https://github.com/sparkfabrik/terraform-gitlab-kubernetes-gitlab-agent/compare/1.1.0...1.2.0)
14+
15+
### Added
16+
17+
- feat: disable autoassign current user by default
18+
1119
## [1.1.0] - 2025-10-08
1220

1321
[Compare with previous version](https://github.com/sparkfabrik/terraform-gitlab-kubernetes-gitlab-agent/compare/1.0.0...1.1.0)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ provider "gitlab" {
7777

7878
## GitLab Agents user membership
7979

80-
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`.
80+
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.
8181

8282
Adding the user as `maintainer` to the newly created project ensures they have the permissions to commit and push to it.
8383

84-
**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
84+
**ATTENTION:** If the current user is already added to the project the apply will fail saying that a membership already exists
8585

8686
<!-- BEGIN_TF_DOCS -->
8787
## Providers

main.tf

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ locals {
5151
(var.gitlab_agent_variable_name_agent_id) : gitlab_cluster_agent.this.name,
5252
(var.gitlab_agent_variable_name_agent_project) : local.project_path_with_namespace,
5353
}
54-
55-
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
5654
}
5755

5856
# Gitlab resources
@@ -87,19 +85,14 @@ data "gitlab_project" "enabled_projects" {
8785
path_with_namespace = each.value
8886
}
8987

90-
# Data source to get all the memberships for the project
91-
data "gitlab_project_membership" "this" {
92-
project_id = local.project_id
93-
}
94-
9588
resource "gitlab_project" "project" {
9689
count = local.use_existing_project == 0 ? 1 : 0
9790
name = var.gitlab_project_name
9891
namespace_id = var.operate_at_root_group_level ? data.gitlab_group.root_namespace.group_id : data.gitlab_group.parent_group[0].group_id
9992
}
10093

10194
resource "gitlab_project_membership" "project" {
102-
count = var.autoassign_current_user_as_maintainer && !local.current_user_is_maintainer_of_project ? 1 : 0
95+
count = var.assign_current_user_as_maintainer ? 1 : 0
10396
project = local.project_id
10497
user_id = data.gitlab_current_user.this.id
10598
access_level = "maintainer"

variables.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ variable "create_default_pod_anti_affinity" {
156156
default = true
157157
}
158158

159-
variable "autoassign_current_user_as_maintainer" {
160-
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."
159+
variable "assign_current_user_as_maintainer" {
160+
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."
161161
type = bool
162-
default = true
162+
default = false
163163
}

0 commit comments

Comments
 (0)