From 23f7ef13540631875fc11b0ecc431d78c1d37412 Mon Sep 17 00:00:00 2001 From: Stefano Sibilia <24303019+Stevesibilia@users.noreply.github.com.> Date: Mon, 21 Oct 2024 12:28:27 +0200 Subject: [PATCH 01/29] refs platform/#3152: add variable for project --- main.tf | 8 ++++++++ variables.tf | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/main.tf b/main.tf index 051d87e..e8dace3 100644 --- a/main.tf +++ b/main.tf @@ -25,6 +25,14 @@ locals { } # Gitlab resources + +resource "gitlab_project" "project" { + count = var.gitlab_project_details ? 0 : 1 + name = var.gitlab_project_details.name + namespace_id = var.gitlab.project_details.group + description = var.gitlab_project_details.description +} + data "gitlab_project" "this" { path_with_namespace = var.gitlab_project_path_with_namespace } diff --git a/variables.tf b/variables.tf index e7b7d86..32c3fd1 100644 --- a/variables.tf +++ b/variables.tf @@ -1,3 +1,17 @@ +variable "gitlab_project_details" { + description = "Details of the Gitlab project including name, group, and description" + type = object({ + name = string + group = string + description = string + }) + default = { + name = "" + group = "" + description = "" + } +} + variable "gitlab_project_path_with_namespace" { description = "The path with namespace of the Gitlab project that hosts the Gitlab Agent configuration. The project must be created in Gitlab before running this module. The configured Gitlab provider must have write access to the project." type = string From a44ed5d092d505a3159c17af782449bd346f0933 Mon Sep 17 00:00:00 2001 From: Stefano Sibilia <24303019+Stevesibilia@users.noreply.github.com.> Date: Mon, 21 Oct 2024 12:36:01 +0200 Subject: [PATCH 02/29] refs platform/#3152: fix --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index e8dace3..5bb0d4e 100644 --- a/main.tf +++ b/main.tf @@ -29,7 +29,7 @@ locals { resource "gitlab_project" "project" { count = var.gitlab_project_details ? 0 : 1 name = var.gitlab_project_details.name - namespace_id = var.gitlab.project_details.group + namespace_id = var.gitlab_project_details.group description = var.gitlab_project_details.description } From 854207b176f1df213ecaa18aef628f582fbd6a1b Mon Sep 17 00:00:00 2001 From: Stefano Sibilia <24303019+Stevesibilia@users.noreply.github.com.> Date: Mon, 21 Oct 2024 12:41:22 +0200 Subject: [PATCH 03/29] ref platform/#3152: fix condition --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 5bb0d4e..a09beec 100644 --- a/main.tf +++ b/main.tf @@ -27,7 +27,7 @@ locals { # Gitlab resources resource "gitlab_project" "project" { - count = var.gitlab_project_details ? 0 : 1 + count = var.gitlab_project_details.name ? 0 : 1 name = var.gitlab_project_details.name namespace_id = var.gitlab_project_details.group description = var.gitlab_project_details.description From e10062b4507c0c54c41d6141ea65077b08c2f08e Mon Sep 17 00:00:00 2001 From: Stefano Sibilia <24303019+Stevesibilia@users.noreply.github.com.> Date: Mon, 21 Oct 2024 12:47:19 +0200 Subject: [PATCH 04/29] refs platform/#3152: fix condition --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index a09beec..199cfbb 100644 --- a/main.tf +++ b/main.tf @@ -27,7 +27,7 @@ locals { # Gitlab resources resource "gitlab_project" "project" { - count = var.gitlab_project_details.name ? 0 : 1 + count = lenght(var.gitlab_project_details.name) > 0 ? 0 : 1 name = var.gitlab_project_details.name namespace_id = var.gitlab_project_details.group description = var.gitlab_project_details.description From a93014a70757079be67721589cc01d74c132404b Mon Sep 17 00:00:00 2001 From: Stefano Sibilia <24303019+Stevesibilia@users.noreply.github.com.> Date: Mon, 21 Oct 2024 12:48:45 +0200 Subject: [PATCH 05/29] ref platform/#3152: typo --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 199cfbb..0cfc28d 100644 --- a/main.tf +++ b/main.tf @@ -27,7 +27,7 @@ locals { # Gitlab resources resource "gitlab_project" "project" { - count = lenght(var.gitlab_project_details.name) > 0 ? 0 : 1 + count = length(var.gitlab_project_details.name) > 0 ? 0 : 1 name = var.gitlab_project_details.name namespace_id = var.gitlab_project_details.group description = var.gitlab_project_details.description From c4664a1076918f61585b7602ea503b36478e8246 Mon Sep 17 00:00:00 2001 From: Stefano Sibilia <24303019+Stevesibilia@users.noreply.github.com.> Date: Mon, 21 Oct 2024 14:14:48 +0200 Subject: [PATCH 06/29] refs platform/#3152: add root namespace --- main.tf | 5 +++-- variables.tf | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index 0cfc28d..46b1090 100644 --- a/main.tf +++ b/main.tf @@ -29,7 +29,7 @@ locals { resource "gitlab_project" "project" { count = length(var.gitlab_project_details.name) > 0 ? 0 : 1 name = var.gitlab_project_details.name - namespace_id = var.gitlab_project_details.group + namespace_id = data.gitlab_group.root_namespace.group_id description = var.gitlab_project_details.description } @@ -38,7 +38,8 @@ data "gitlab_project" "this" { } data "gitlab_group" "root_namespace" { - group_id = data.gitlab_project.this.namespace_id + #group_id = data.gitlab_project.this.namespace_id + full_path = var.gitlab_root_namespace } resource "gitlab_cluster_agent" "this" { diff --git a/variables.tf b/variables.tf index 32c3fd1..32074b1 100644 --- a/variables.tf +++ b/variables.tf @@ -12,6 +12,11 @@ variable "gitlab_project_details" { } } +variable "gitlab_root_namespace" { + description = "The full path of the root namespace in Gitlab. This is the namespace where the Gitlab Agent will be granted access." + type = string +} + variable "gitlab_project_path_with_namespace" { description = "The path with namespace of the Gitlab project that hosts the Gitlab Agent configuration. The project must be created in Gitlab before running this module. The configured Gitlab provider must have write access to the project." type = string From 1a73e448a5b4b4c75d11cd6c47f41cc6ddac6580 Mon Sep 17 00:00:00 2001 From: Stefano Sibilia <24303019+Stevesibilia@users.noreply.github.com.> Date: Mon, 21 Oct 2024 14:16:51 +0200 Subject: [PATCH 07/29] refs platform/#3152: fix condition --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 46b1090..a57358d 100644 --- a/main.tf +++ b/main.tf @@ -27,7 +27,7 @@ locals { # Gitlab resources resource "gitlab_project" "project" { - count = length(var.gitlab_project_details.name) > 0 ? 0 : 1 + count = length(var.gitlab_project_details.name) > 0 ? 1 : 0 name = var.gitlab_project_details.name namespace_id = data.gitlab_group.root_namespace.group_id description = var.gitlab_project_details.description From 747523e35fe8a24c016168de23f07b6290bd08a6 Mon Sep 17 00:00:00 2001 From: Stefano Sibilia <24303019+Stevesibilia@users.noreply.github.com.> Date: Mon, 21 Oct 2024 15:04:46 +0200 Subject: [PATCH 08/29] refs platform/#3152: add project creation --- main.tf | 11 +++++++---- variables.tf | 5 ++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/main.tf b/main.tf index a57358d..4a09fed 100644 --- a/main.tf +++ b/main.tf @@ -22,6 +22,9 @@ locals { (var.gitlab_agent_variable_name_agent_id) : gitlab_cluster_agent.this.name, (var.gitlab_agent_variable_name_agent_project) : data.gitlab_project.this.path_with_namespace, } + + project_id = length(gitlab_project.project.id) > 0 ? gitlab_project.project[0].id : data.gitlab_project.this.id + } # Gitlab resources @@ -30,10 +33,10 @@ resource "gitlab_project" "project" { count = length(var.gitlab_project_details.name) > 0 ? 1 : 0 name = var.gitlab_project_details.name namespace_id = data.gitlab_group.root_namespace.group_id - description = var.gitlab_project_details.description } data "gitlab_project" "this" { + count = length(var.gitlab_project_details.name) > 0 ? 0 : 1 path_with_namespace = var.gitlab_project_path_with_namespace } @@ -43,12 +46,12 @@ data "gitlab_group" "root_namespace" { } resource "gitlab_cluster_agent" "this" { - project = data.gitlab_project.this.id + project = locals.project_id name = var.gitlab_agent_name } resource "gitlab_cluster_agent_token" "this" { - project = data.gitlab_project.this.id + project = locals.project_id agent_id = gitlab_cluster_agent.this.agent_id name = local.gitlab_agent_token_name_computed description = local.gitlab_agent_token_description_computed @@ -57,7 +60,7 @@ resource "gitlab_cluster_agent_token" "this" { resource "gitlab_repository_file" "this" { count = trimspace(local.final_configuration_file_content) != "" ? 1 : 0 - project = data.gitlab_project.this.id + project = locals.project_id branch = var.gitlab_agent_branch_name commit_message = local.gitlab_agent_commmit_message_computed file_path = ".gitlab/agents/${gitlab_cluster_agent.this.name}/config.yaml" diff --git a/variables.tf b/variables.tf index 32074b1..5baab13 100644 --- a/variables.tf +++ b/variables.tf @@ -1,9 +1,8 @@ variable "gitlab_project_details" { description = "Details of the Gitlab project including name, group, and description" type = object({ - name = string - group = string - description = string + name = string + group = string }) default = { name = "" From fc344bd128c6623b7725e4d7c7273014aa6b44ca Mon Sep 17 00:00:00 2001 From: Stefano Sibilia <24303019+Stevesibilia@users.noreply.github.com.> Date: Mon, 21 Oct 2024 15:07:46 +0200 Subject: [PATCH 09/29] refs platfomr/#3152: fix --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 4a09fed..c7b940d 100644 --- a/main.tf +++ b/main.tf @@ -23,7 +23,7 @@ locals { (var.gitlab_agent_variable_name_agent_project) : data.gitlab_project.this.path_with_namespace, } - project_id = length(gitlab_project.project.id) > 0 ? gitlab_project.project[0].id : data.gitlab_project.this.id + project_id = length(gitlab_project.project[0].id) > 0 ? gitlab_project.project[0].id : data.gitlab_project.this.id } From 6cd5345b99ed7c7c70c27fd02961b186cd369887 Mon Sep 17 00:00:00 2001 From: Stefano Sibilia <24303019+Stevesibilia@users.noreply.github.com.> Date: Mon, 21 Oct 2024 15:10:41 +0200 Subject: [PATCH 10/29] ref platform/#3152: fix count --- main.tf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.tf b/main.tf index c7b940d..872c44f 100644 --- a/main.tf +++ b/main.tf @@ -23,7 +23,8 @@ locals { (var.gitlab_agent_variable_name_agent_project) : data.gitlab_project.this.path_with_namespace, } - project_id = length(gitlab_project.project[0].id) > 0 ? gitlab_project.project[0].id : data.gitlab_project.this.id + project_id = length(gitlab_project.project[0].id) > 0 ? gitlab_project.project[0].id : data.gitlab_project.this.id[count.index] + } From 534eb754b52b50506fe13c5ec6367f79034b9eb0 Mon Sep 17 00:00:00 2001 From: Stefano Sibilia <24303019+Stevesibilia@users.noreply.github.com.> Date: Mon, 21 Oct 2024 15:13:23 +0200 Subject: [PATCH 11/29] fix --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 872c44f..807e1b2 100644 --- a/main.tf +++ b/main.tf @@ -23,7 +23,7 @@ locals { (var.gitlab_agent_variable_name_agent_project) : data.gitlab_project.this.path_with_namespace, } - project_id = length(gitlab_project.project[0].id) > 0 ? gitlab_project.project[0].id : data.gitlab_project.this.id[count.index] + project_id = length(gitlab_project.project[0].id) > 0 ? gitlab_project.project[0].id : data.gitlab_project.this.id[0] } From 3500b812e3b98a051d3cf0c005ab2a3554d825a0 Mon Sep 17 00:00:00 2001 From: Stefano Sibilia <24303019+Stevesibilia@users.noreply.github.com.> Date: Mon, 21 Oct 2024 15:15:30 +0200 Subject: [PATCH 12/29] fix --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 807e1b2..02b3471 100644 --- a/main.tf +++ b/main.tf @@ -23,7 +23,7 @@ locals { (var.gitlab_agent_variable_name_agent_project) : data.gitlab_project.this.path_with_namespace, } - project_id = length(gitlab_project.project[0].id) > 0 ? gitlab_project.project[0].id : data.gitlab_project.this.id[0] + project_id = length(gitlab_project.project[0].id) > 0 ? gitlab_project.project[0].id : data.gitlab_project.this[0].id } From 81feff53449847186043e15accedd3a3ecf8a75e Mon Sep 17 00:00:00 2001 From: Stefano Sibilia <24303019+Stevesibilia@users.noreply.github.com.> Date: Mon, 21 Oct 2024 15:22:30 +0200 Subject: [PATCH 13/29] fix --- main.tf | 8 +++++--- outputs.tf | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/main.tf b/main.tf index 02b3471..6de7a14 100644 --- a/main.tf +++ b/main.tf @@ -47,12 +47,13 @@ data "gitlab_group" "root_namespace" { } resource "gitlab_cluster_agent" "this" { - project = locals.project_id + project = local.project_id name = var.gitlab_agent_name } resource "gitlab_cluster_agent_token" "this" { - project = locals.project_id + project = local.project_id + agent_id = gitlab_cluster_agent.this.agent_id name = local.gitlab_agent_token_name_computed description = local.gitlab_agent_token_description_computed @@ -61,7 +62,8 @@ resource "gitlab_cluster_agent_token" "this" { resource "gitlab_repository_file" "this" { count = trimspace(local.final_configuration_file_content) != "" ? 1 : 0 - project = locals.project_id + project = local.project_id + branch = var.gitlab_agent_branch_name commit_message = local.gitlab_agent_commmit_message_computed file_path = ".gitlab/agents/${gitlab_cluster_agent.this.name}/config.yaml" diff --git a/outputs.tf b/outputs.tf index bf12857..e6166f2 100644 --- a/outputs.tf +++ b/outputs.tf @@ -21,7 +21,7 @@ output "gitlab_agent_kubernetes_context_variables" { output "gitlab_agents_project_id" { description = "The ID of the Gitlab project where the Gitlab Agents are installed." - value = data.gitlab_project.this.id + value = local.project_id } output "gitlab_root_namespace_id" { From 368c9bfe9bde3f0f354b410b0ba32e9fe866f638 Mon Sep 17 00:00:00 2001 From: Stefano Sibilia <24303019+Stevesibilia@users.noreply.github.com.> Date: Mon, 21 Oct 2024 15:25:45 +0200 Subject: [PATCH 14/29] fix --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 6de7a14..7af01b8 100644 --- a/main.tf +++ b/main.tf @@ -20,7 +20,7 @@ locals { # Gitlab Agent CI/CD variables gitlab_agent_kubernetes_context_variables = { (var.gitlab_agent_variable_name_agent_id) : gitlab_cluster_agent.this.name, - (var.gitlab_agent_variable_name_agent_project) : data.gitlab_project.this.path_with_namespace, + (var.gitlab_agent_variable_name_agent_project) : data.gitlab_project.this[0].path_with_namespace, } project_id = length(gitlab_project.project[0].id) > 0 ? gitlab_project.project[0].id : data.gitlab_project.this[0].id From f3302f119bb009156789619b6773856bdc76c8c3 Mon Sep 17 00:00:00 2001 From: Stefano Sibilia <24303019+Stevesibilia@users.noreply.github.com.> Date: Mon, 21 Oct 2024 15:36:00 +0200 Subject: [PATCH 15/29] fix --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 7af01b8..dc6246f 100644 --- a/main.tf +++ b/main.tf @@ -43,7 +43,7 @@ data "gitlab_project" "this" { data "gitlab_group" "root_namespace" { #group_id = data.gitlab_project.this.namespace_id - full_path = var.gitlab_root_namespace + full_path = var.gitlab_project_details.group } resource "gitlab_cluster_agent" "this" { From 96a552fb053f1fd4d039a40199063e3d882deaed Mon Sep 17 00:00:00 2001 From: Stefano Sibilia <24303019+Stevesibilia@users.noreply.github.com.> Date: Mon, 21 Oct 2024 16:00:42 +0200 Subject: [PATCH 16/29] refs platform/#3152: cleaned conditions --- main.tf | 10 +++++----- variables.tf | 6 ++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/main.tf b/main.tf index dc6246f..169c730 100644 --- a/main.tf +++ b/main.tf @@ -22,8 +22,8 @@ locals { (var.gitlab_agent_variable_name_agent_id) : gitlab_cluster_agent.this.name, (var.gitlab_agent_variable_name_agent_project) : data.gitlab_project.this[0].path_with_namespace, } - - project_id = length(gitlab_project.project[0].id) > 0 ? gitlab_project.project[0].id : data.gitlab_project.this[0].id + use_existing_project = var.gitlab_project_name == "" ? 1 : 0 + project_id = local.use_existing_project == 1 ? data.gitlab_project.this[0].id : gitlab_project.project[0].id } @@ -31,13 +31,13 @@ locals { # Gitlab resources resource "gitlab_project" "project" { - count = length(var.gitlab_project_details.name) > 0 ? 1 : 0 - name = var.gitlab_project_details.name + count = local.use_existing_project == 0 ? 1 : 0 + name = var.gitlab_project_name namespace_id = data.gitlab_group.root_namespace.group_id } data "gitlab_project" "this" { - count = length(var.gitlab_project_details.name) > 0 ? 0 : 1 + count = local.use_existing_project path_with_namespace = var.gitlab_project_path_with_namespace } diff --git a/variables.tf b/variables.tf index 5baab13..a42893e 100644 --- a/variables.tf +++ b/variables.tf @@ -1,3 +1,9 @@ +variable "gitlab_project_name" { + description = "The name of the Gitlab project that hosts the Gitlab Agent configuration. If not provided, the module will use the project defined in `gitlab_project_path_with_namespace`." + type = string + default = "" +} + variable "gitlab_project_details" { description = "Details of the Gitlab project including name, group, and description" type = object({ From f6f571877384ee0e7d1e0af5cfca40e410a1bf1c Mon Sep 17 00:00:00 2001 From: Stefano Sibilia <24303019+Stevesibilia@users.noreply.github.com.> Date: Mon, 21 Oct 2024 16:03:37 +0200 Subject: [PATCH 17/29] fix --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 169c730..b57a3b6 100644 --- a/main.tf +++ b/main.tf @@ -43,7 +43,7 @@ data "gitlab_project" "this" { data "gitlab_group" "root_namespace" { #group_id = data.gitlab_project.this.namespace_id - full_path = var.gitlab_project_details.group + full_path = var.gitlab_root_namespace } resource "gitlab_cluster_agent" "this" { From f21fd598732889d413afe6da5285329a065432ab Mon Sep 17 00:00:00 2001 From: Stefano Sibilia <24303019+Stevesibilia@users.noreply.github.com.> Date: Mon, 21 Oct 2024 16:36:45 +0200 Subject: [PATCH 18/29] fix --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index b57a3b6..fe1f9af 100644 --- a/main.tf +++ b/main.tf @@ -20,7 +20,7 @@ locals { # Gitlab Agent CI/CD variables gitlab_agent_kubernetes_context_variables = { (var.gitlab_agent_variable_name_agent_id) : gitlab_cluster_agent.this.name, - (var.gitlab_agent_variable_name_agent_project) : data.gitlab_project.this[0].path_with_namespace, + (var.gitlab_agent_variable_name_agent_project) : local.use_existing_project == 1 ? data.gitlab_project.this[0].path_with_namespace : gitlab_project.project[0].path_with_namespace, } use_existing_project = var.gitlab_project_name == "" ? 1 : 0 project_id = local.use_existing_project == 1 ? data.gitlab_project.this[0].id : gitlab_project.project[0].id From 369b82ac3e6cda4ae3ca8b9f47ccef9174de05e2 Mon Sep 17 00:00:00 2001 From: Stefano Sibilia <24303019+Stevesibilia@users.noreply.github.com.> Date: Mon, 21 Oct 2024 16:49:10 +0200 Subject: [PATCH 19/29] refs platform/#3152: remove unused variables --- main.tf | 7 +++---- variables.tf | 13 ------------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/main.tf b/main.tf index fe1f9af..2d62699 100644 --- a/main.tf +++ b/main.tf @@ -9,6 +9,9 @@ locals { final_namespace = var.create_namespace ? resource.kubernetes_namespace_v1.this[0].metadata[0].name : data.kubernetes_namespace_v1.this[0].metadata[0].name + use_existing_project = var.gitlab_project_name == "" ? 1 : 0 + project_id = local.use_existing_project == 1 ? data.gitlab_project.this[0].id : gitlab_project.project[0].id + gitlab_agent_token_name_computed = replace(var.gitlab_agent_token_name, "{{gitlab_agent_name}}", var.gitlab_agent_name) gitlab_agent_token_description_computed = replace(var.gitlab_agent_token_description, "{{gitlab_agent_name}}", var.gitlab_agent_name) gitlab_agent_commmit_message_computed = replace(var.gitlab_agent_commmit_message, "{{gitlab_agent_name}}", var.gitlab_agent_name) @@ -22,10 +25,6 @@ locals { (var.gitlab_agent_variable_name_agent_id) : gitlab_cluster_agent.this.name, (var.gitlab_agent_variable_name_agent_project) : local.use_existing_project == 1 ? data.gitlab_project.this[0].path_with_namespace : gitlab_project.project[0].path_with_namespace, } - use_existing_project = var.gitlab_project_name == "" ? 1 : 0 - project_id = local.use_existing_project == 1 ? data.gitlab_project.this[0].id : gitlab_project.project[0].id - - } # Gitlab resources diff --git a/variables.tf b/variables.tf index a42893e..9ea6304 100644 --- a/variables.tf +++ b/variables.tf @@ -4,19 +4,6 @@ variable "gitlab_project_name" { default = "" } -variable "gitlab_project_details" { - description = "Details of the Gitlab project including name, group, and description" - type = object({ - name = string - group = string - }) - default = { - name = "" - group = "" - description = "" - } -} - variable "gitlab_root_namespace" { description = "The full path of the root namespace in Gitlab. This is the namespace where the Gitlab Agent will be granted access." type = string From 7e492ae28f2cd29ef32a7408c56d504c90c37518 Mon Sep 17 00:00:00 2001 From: Stefano Sibilia <24303019+Stevesibilia@users.noreply.github.com.> Date: Mon, 21 Oct 2024 17:03:03 +0200 Subject: [PATCH 20/29] refs platform/#3152: add docs --- CHANGELOG.md | 8 ++++++++ README.md | 2 ++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b473b0..94528f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,14 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +## [0.7.0] - 2024-10-21 + +[Compare with previous version](https://github.com/sparkfabrik/terraform-gitlab-kubernetes-gitlab-agent/compare/0.6.0...0.7.0) + +### Added + +- The module can create the gitlab agents project by setting the variable `gitlab_project_name` + ## [0.6.0] - 2024-07-30 [Compare with previous version](https://github.com/sparkfabrik/terraform-gitlab-kubernetes-gitlab-agent/compare/0.5.0...0.6.0) diff --git a/README.md b/README.md index ce3a35a..d4fa020 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ If required (`gitlab_agent_grant_access_to_entire_root_namespace` configured to **ATTENTION**: you have to manually create the project that will host the Gitlab Agent configuration in Gitlab before running this module. +From version 0.7.0 if you set `gitlab_project_name` the module will create gitlab project automatically. This new behavior requires the provider to have the proper permissions to create the project in the namespace. + ## RBAC configuration for the Gitlab Agent service account This module uses the default configuration of the Gitlab Agent Helm chart. The default configuration grants to the Gitlab Agent service account the `cluster-admin` ClusterRole. If you want to change this configuration, you can use the `helm_additional_values` variable to pass additional values to the Helm chart. From 1f503cc7db24a19eaeac26e0d2e23be48a1c857b Mon Sep 17 00:00:00 2001 From: Stefano Sibilia <24303019+Stevesibilia@users.noreply.github.com.> Date: Mon, 21 Oct 2024 18:13:23 +0200 Subject: [PATCH 21/29] ref platform/#3152: change kas address to metadata.kas.external_url --- main.tf | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/main.tf b/main.tf index 2d62699..5047ea4 100644 --- a/main.tf +++ b/main.tf @@ -28,12 +28,7 @@ locals { } # Gitlab resources - -resource "gitlab_project" "project" { - count = local.use_existing_project == 0 ? 1 : 0 - name = var.gitlab_project_name - namespace_id = data.gitlab_group.root_namespace.group_id -} +data "gitlab_metadata" "this" {} data "gitlab_project" "this" { count = local.use_existing_project @@ -45,6 +40,12 @@ data "gitlab_group" "root_namespace" { full_path = var.gitlab_root_namespace } +resource "gitlab_project" "project" { + count = local.use_existing_project == 0 ? 1 : 0 + name = var.gitlab_project_name + namespace_id = data.gitlab_group.root_namespace.group_id +} + resource "gitlab_cluster_agent" "this" { project = local.project_id name = var.gitlab_agent_name @@ -141,7 +142,7 @@ resource "helm_release" "this" { { k8s_common_labels = local.k8s_common_labels agent_replicas = var.agent_replicas - agent_kas_address = var.agent_kas_address + agent_kas_address = data.gitlab_metadata.this.kas.external_url agent_token_secret_name = kubernetes_secret_v1.gitlab_agent_token_secret.metadata[0].name # Variables used to configure the default podAntiAffinity for the Gitlab Agent create_default_pod_anti_affinity = var.create_default_pod_anti_affinity From ff98fc13525757499016692d0244637c7a49bea5 Mon Sep 17 00:00:00 2001 From: Stefano Sibilia <24303019+Stevesibilia@users.noreply.github.com.> Date: Mon, 21 Oct 2024 18:16:50 +0200 Subject: [PATCH 22/29] refs platform/#3152: fix kass address --- files/values.yaml.tftpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/values.yaml.tftpl b/files/values.yaml.tftpl index 874ced3..9224686 100644 --- a/files/values.yaml.tftpl +++ b/files/values.yaml.tftpl @@ -10,7 +10,7 @@ additionalLabels: replicas: ${agent_replicas} config: - kasAddress: "wss://${agent_kas_address}" + kasAddress: "${agent_kas_address}" secretName: "${agent_token_secret_name}" resources: From 70bd82cf4282428ce5a621198e2ac1f7d2596952 Mon Sep 17 00:00:00 2001 From: Stefano Sibilia <24303019+Stevesibilia@users.noreply.github.com.> Date: Mon, 21 Oct 2024 18:26:02 +0200 Subject: [PATCH 23/29] refs platform/#3152: remove var agent_kas_address --- variables.tf | 6 ------ 1 file changed, 6 deletions(-) diff --git a/variables.tf b/variables.tf index 9ea6304..8829633 100644 --- a/variables.tf +++ b/variables.tf @@ -143,12 +143,6 @@ variable "agent_replicas" { default = 1 } -variable "agent_kas_address" { - description = "The address of the Gitlab Kubernetes Agent Server (KAS)." - type = string - default = "kas.gitlab.com" -} - variable "create_default_pod_anti_affinity" { description = "Create default podAntiAffinity rules for the Gitlab Agent pods." type = bool From c829084123999ce63ebf3da615731349faa72bbb Mon Sep 17 00:00:00 2001 From: Stefano Sibilia <24303019+Stevesibilia@users.noreply.github.com> Date: Tue, 22 Oct 2024 10:45:06 +0200 Subject: [PATCH 24/29] Update CHANGELOG.md Co-authored-by: Daniele Monti <62102073+Monska85@users.noreply.github.com> --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94528f9..9419fa7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,13 +8,13 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] -## [0.7.0] - 2024-10-21 +## [0.7.0] - 2024-10-22 [Compare with previous version](https://github.com/sparkfabrik/terraform-gitlab-kubernetes-gitlab-agent/compare/0.6.0...0.7.0) ### Added -- The module can create the gitlab agents project by setting the variable `gitlab_project_name` +- The module can create the gitlab agents project by setting the variable `gitlab_project_name`. ## [0.6.0] - 2024-07-30 From 092706ba32aae949d0124f234862e552e2ebd4ab Mon Sep 17 00:00:00 2001 From: Stefano Sibilia <24303019+Stevesibilia@users.noreply.github.com> Date: Tue, 22 Oct 2024 10:45:13 +0200 Subject: [PATCH 25/29] Update main.tf Co-authored-by: Daniele Monti <62102073+Monska85@users.noreply.github.com> --- main.tf | 1 - 1 file changed, 1 deletion(-) diff --git a/main.tf b/main.tf index 5047ea4..37b4403 100644 --- a/main.tf +++ b/main.tf @@ -36,7 +36,6 @@ data "gitlab_project" "this" { } data "gitlab_group" "root_namespace" { - #group_id = data.gitlab_project.this.namespace_id full_path = var.gitlab_root_namespace } From cac9b3a8cb33f66dfc48d3e9bf4db758db51d8e6 Mon Sep 17 00:00:00 2001 From: Stefano Sibilia <24303019+Stevesibilia@users.noreply.github.com> Date: Tue, 22 Oct 2024 10:45:26 +0200 Subject: [PATCH 26/29] Update README.md Co-authored-by: Daniele Monti <62102073+Monska85@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d4fa020..cce0b65 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ If required (`gitlab_agent_grant_access_to_entire_root_namespace` configured to **ATTENTION**: you have to manually create the project that will host the Gitlab Agent configuration in Gitlab before running this module. -From version 0.7.0 if you set `gitlab_project_name` the module will create gitlab project automatically. This new behavior requires the provider to have the proper permissions to create the project in the namespace. +From version `0.7.0`, if you set `gitlab_project_name` the module will create Gitlab project automatically. This new behavior requires the provider to have the proper permissions to create the project in the namespace. ## RBAC configuration for the Gitlab Agent service account From 1bae9783ddfd6a267bcf96431125b8764a10fa01 Mon Sep 17 00:00:00 2001 From: Stefano Sibilia <24303019+Stevesibilia@users.noreply.github.com> Date: Tue, 22 Oct 2024 10:45:39 +0200 Subject: [PATCH 27/29] Update main.tf Co-authored-by: Daniele Monti <62102073+Monska85@users.noreply.github.com> --- main.tf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 37b4403..b6ab848 100644 --- a/main.tf +++ b/main.tf @@ -10,7 +10,8 @@ locals { final_namespace = var.create_namespace ? resource.kubernetes_namespace_v1.this[0].metadata[0].name : data.kubernetes_namespace_v1.this[0].metadata[0].name use_existing_project = var.gitlab_project_name == "" ? 1 : 0 - project_id = local.use_existing_project == 1 ? data.gitlab_project.this[0].id : gitlab_project.project[0].id + project_id = local.use_existing_project == 1 ? data.gitlab_project.this[0].id : gitlab_project.project[0].id + project_path_with_namespace = local.use_existing_project == 1 ? data.gitlab_project.this[0].path_with_namespace : gitlab_project.project[0].path_with_namespace gitlab_agent_token_name_computed = replace(var.gitlab_agent_token_name, "{{gitlab_agent_name}}", var.gitlab_agent_name) gitlab_agent_token_description_computed = replace(var.gitlab_agent_token_description, "{{gitlab_agent_name}}", var.gitlab_agent_name) From 622fd6cb7a64c1ff7439d00359e5bfd3f60a6c0e Mon Sep 17 00:00:00 2001 From: Stefano Sibilia <24303019+Stevesibilia@users.noreply.github.com> Date: Tue, 22 Oct 2024 10:45:46 +0200 Subject: [PATCH 28/29] Update main.tf Co-authored-by: Daniele Monti <62102073+Monska85@users.noreply.github.com> --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index b6ab848..b2d3df8 100644 --- a/main.tf +++ b/main.tf @@ -24,7 +24,7 @@ locals { # Gitlab Agent CI/CD variables gitlab_agent_kubernetes_context_variables = { (var.gitlab_agent_variable_name_agent_id) : gitlab_cluster_agent.this.name, - (var.gitlab_agent_variable_name_agent_project) : local.use_existing_project == 1 ? data.gitlab_project.this[0].path_with_namespace : gitlab_project.project[0].path_with_namespace, + (var.gitlab_agent_variable_name_agent_project) : local.project_path_with_namespace, } } From f173b17017abd8767f37744bbdf7871978b7f29b Mon Sep 17 00:00:00 2001 From: Stefano Sibilia <24303019+Stevesibilia@users.noreply.github.com.> Date: Tue, 22 Oct 2024 11:37:44 +0200 Subject: [PATCH 29/29] refs platform/#3152: change gitlab_root_namespace with local project_path_with_namespace --- main.tf | 7 ++++--- variables.tf | 5 ----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/main.tf b/main.tf index b2d3df8..cc7987e 100644 --- a/main.tf +++ b/main.tf @@ -9,9 +9,10 @@ locals { final_namespace = var.create_namespace ? resource.kubernetes_namespace_v1.this[0].metadata[0].name : data.kubernetes_namespace_v1.this[0].metadata[0].name - use_existing_project = var.gitlab_project_name == "" ? 1 : 0 - project_id = local.use_existing_project == 1 ? data.gitlab_project.this[0].id : gitlab_project.project[0].id + use_existing_project = var.gitlab_project_name == "" ? 1 : 0 + project_id = local.use_existing_project == 1 ? data.gitlab_project.this[0].id : gitlab_project.project[0].id project_path_with_namespace = local.use_existing_project == 1 ? data.gitlab_project.this[0].path_with_namespace : gitlab_project.project[0].path_with_namespace + project_root_namespace = split("/", var.gitlab_project_path_with_namespace)[0] gitlab_agent_token_name_computed = replace(var.gitlab_agent_token_name, "{{gitlab_agent_name}}", var.gitlab_agent_name) gitlab_agent_token_description_computed = replace(var.gitlab_agent_token_description, "{{gitlab_agent_name}}", var.gitlab_agent_name) @@ -37,7 +38,7 @@ data "gitlab_project" "this" { } data "gitlab_group" "root_namespace" { - full_path = var.gitlab_root_namespace + full_path = local.project_root_namespace } resource "gitlab_project" "project" { diff --git a/variables.tf b/variables.tf index 8829633..0fc19c3 100644 --- a/variables.tf +++ b/variables.tf @@ -4,11 +4,6 @@ variable "gitlab_project_name" { default = "" } -variable "gitlab_root_namespace" { - description = "The full path of the root namespace in Gitlab. This is the namespace where the Gitlab Agent will be granted access." - type = string -} - variable "gitlab_project_path_with_namespace" { description = "The path with namespace of the Gitlab project that hosts the Gitlab Agent configuration. The project must be created in Gitlab before running this module. The configured Gitlab provider must have write access to the project." type = string