Skip to content

Commit 0f90aa5

Browse files
authored
Merge pull request #1 from sparkfabrik/feat/add_dependency_for_gitlab_vars
feat: add dependency for the Gitlab variables and allow customization for Gitlab Agent configuration file
2 parents 47c729f + 6894b8e commit 0f90aa5

File tree

6 files changed

+35
-3
lines changed

6 files changed

+35
-3
lines changed

CHANGELOG.md

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

99
## [Unreleased]
1010

11+
## [0.2.0] - 2024-07-04
12+
13+
[Compare with previous version](https://github.com/sparkfabrik/terraform-gitlab-kubernetes-gitlab-agent/compare/0.1.0...0.2.0)
14+
15+
- Add dependency on the Gitlab variables to prevent their creation before the helm release.
16+
- Add the `gitlab_agent_append_to_config_file` variable to allow customizations to the agent configuration file keeping the access for the root namespace managed by the module.
17+
1118
## [0.1.0] - 2024-06-27
1219

1320
- First release.

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
TERRAFORM_DOCS_VERSION ?= 0.18.0
2+
13
.PHONY: lint tfscan generate-docs
24

35
lint:
@@ -10,4 +12,4 @@ generate-docs: lint
1012
docker run --rm -u $$(id -u) \
1113
--volume "$(PWD):/terraform-docs" \
1214
-w /terraform-docs \
13-
quay.io/terraform-docs/terraform-docs:0.16.0 markdown table --config .terraform-docs.yml --output-file README.md --output-mode inject .
15+
quay.io/terraform-docs/terraform-docs:$(TERRAFORM_DOCS_VERSION) markdown table --config .terraform-docs.yml --output-file README.md --output-mode inject .

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ provider "gitlab" {
5050
| <a name="input_agent_kas_address"></a> [agent\_kas\_address](#input\_agent\_kas\_address) | The address of the Gitlab Kubernetes Agent Server (KAS). | `string` | `"kas.gitlab.com"` | no |
5151
| <a name="input_agent_replicas"></a> [agent\_replicas](#input\_agent\_replicas) | The number of replicas of the Gitlab Agent. | `number` | `1` | no |
5252
| <a name="input_create_namespace"></a> [create\_namespace](#input\_create\_namespace) | Create namespace for the helm release. If false, the namespace must be created before using this module. | `bool` | `true` | no |
53+
| <a name="input_gitlab_agent_append_to_config_file"></a> [gitlab\_agent\_append\_to\_config\_file](#input\_gitlab\_agent\_append\_to\_config\_file) | Append the Gitlab Agent configuration to the configuration file created for the entire root namespace. This variable is only used when `gitlab_agent_grant_access_to_entire_root_namespace` is true. | `string` | `""` | no |
5354
| <a name="input_gitlab_agent_branch_name"></a> [gitlab\_agent\_branch\_name](#input\_gitlab\_agent\_branch\_name) | The branch name where the Gitlab Agent configuration will be stored. | `string` | `"main"` | no |
5455
| <a name="input_gitlab_agent_commmit_message"></a> [gitlab\_agent\_commmit\_message](#input\_gitlab\_agent\_commmit\_message) | The commit message to use when committing the Gitlab Agent configuration file. You can use the placeholder `{{gitlab_agent_name}}` to reference the Gitlab Agent name. | `string` | `"[CI] Add agent config file for {{gitlab_agent_name}}"` | no |
5556
| <a name="input_gitlab_agent_create_variables_in_root_namespace"></a> [gitlab\_agent\_create\_variables\_in\_root\_namespace](#input\_gitlab\_agent\_create\_variables\_in\_root\_namespace) | Create two Gitlab CI/CD variables in the root namespace useful to configure the Kubernetes context and use the Gitlab Agent. These variables are created in the root namespace of the project defined in `gitlab_project_path_with_namespace`, which is the project that hosts the Gitlab Agent configuration. | `bool` | `true` | no |
@@ -97,5 +98,4 @@ provider "gitlab" {
9798

9899
No modules.
99100

100-
101101
<!-- END_TF_DOCS -->

files/config.yaml.tftpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
ci_access:
22
groups:
33
- id: ${root_namespace}
4+
5+
%{~ if trimspace(gitlab_agent_append_to_config_file) != "" }
6+
${gitlab_agent_append_to_config_file}
7+
%{~ endif ~}

main.tf

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ locals {
1515
k8s_gitlab_agent_token_secret_name_computed = replace(var.k8s_gitlab_agent_token_secret_name, "{{gitlab_agent_name}}", var.gitlab_agent_name)
1616

1717
# Gitlab Agent configuration file
18-
final_configuration_file_content = var.gitlab_agent_custom_config_file_content != "" ? var.gitlab_agent_custom_config_file_content : (var.gitlab_agent_grant_access_to_entire_root_namespace ? templatefile("${path.module}/files/config.yaml.tftpl", { root_namespace = data.gitlab_group.root_namespace.path }) : "")
18+
final_configuration_file_content = var.gitlab_agent_custom_config_file_content != "" ? var.gitlab_agent_custom_config_file_content : (var.gitlab_agent_grant_access_to_entire_root_namespace ? templatefile("${path.module}/files/config.yaml.tftpl", { root_namespace = data.gitlab_group.root_namespace.path, gitlab_agent_append_to_config_file = var.gitlab_agent_append_to_config_file }) : "")
1919

2020
# Gitlab Agent CI/CD variables
2121
gitlab_agent_kubernetes_context_variables = {
@@ -54,6 +54,12 @@ resource "gitlab_repository_file" "this" {
5454
file_path = ".gitlab/agents/${gitlab_cluster_agent.this.name}/config.yaml"
5555
encoding = "text"
5656
content = local.final_configuration_file_content
57+
58+
# Force the creation of the file only after the creation of the helm release.
59+
# This is to avoid the creation of the file before the creation of the agent.
60+
depends_on = [
61+
helm_release.this
62+
]
5763
}
5864

5965
resource "gitlab_group_variable" "this" {
@@ -64,6 +70,12 @@ resource "gitlab_group_variable" "this" {
6470
value = each.value
6571
protected = false
6672
masked = false
73+
74+
# Force the creation of the variables only after the creation of the helm release.
75+
# This is to avoid the use of the agent before the creation of the agent.
76+
depends_on = [
77+
helm_release.this
78+
]
6779
}
6880

6981
# Kubernetes resources

variables.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ variable "gitlab_agent_grant_access_to_entire_root_namespace" {
2626
default = true
2727
}
2828

29+
variable "gitlab_agent_append_to_config_file" {
30+
description = "Append the Gitlab Agent configuration to the configuration file created for the entire root namespace. This variable is only used when `gitlab_agent_grant_access_to_entire_root_namespace` is true."
31+
type = string
32+
default = ""
33+
34+
}
35+
2936
variable "gitlab_agent_custom_config_file_content" {
3037
description = "The content of the Gitlab Agent configuration file. If not provided and `gitlab_agent_grant_access_to_entire_root_namespace` is true, the default configuration file will be used and the root namespace will be granted access to the Gitlab Agent. If you set this variable, it takes precedence over `gitlab_agent_grant_access_to_entire_root_namespace`."
3138
type = string

0 commit comments

Comments
 (0)