Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: disable 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)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. 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.

**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

<!-- BEGIN_TF_DOCS -->
## Providers
Expand Down
4 changes: 1 addition & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@
(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
Expand Down Expand Up @@ -88,7 +86,7 @@
}

# Data source to get all the memberships for the project
data "gitlab_project_membership" "this" {

Check warning on line 89 in main.tf

View workflow job for this annotation

GitHub Actions / tflint (ubuntu-latest)

data "gitlab_project_membership" "this" is declared but not used
project_id = local.project_id
}

Expand All @@ -99,7 +97,7 @@
}

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"
Expand Down
2 changes: 1 addition & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading