initial commit

This commit is contained in:
Aleksander Cynarski 2024-09-14 16:07:11 +02:00
parent b89b538c6e
commit 19c05b8b3b
Signed by: paramah
GPG Key ID: 6A7C0327F517CA88
8 changed files with 84 additions and 8 deletions

View File

@ -1 +1,4 @@
//Data data "gitlab_group" "parent" {
count = var.parent_group != "" ? 1 : 0
full_path = var.parent_group
}

BIN
images/golang.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 195 KiB

BIN
images/typescript.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@ -1,3 +1,13 @@
//Locals
locals { locals {
default_ci_variables = {
for key, var in var.ci_variables : key => merge(
{
description = lookup(var, "description", ""),
protected = lookup(var, "protected", false),
masked = lookup(var, "masked", false),
environment_scope = lookup(var, "environment_scope", "*"),
},
var
)
}
} }

22
main.tf
View File

@ -1 +1,21 @@
//Main resources resource "gitlab_group" "group" {
name = var.name
path = var.name
description = var.description
parent_id = var.parent_group != "" ? data.gitlab_group.parent[0].id : null
avatar = var.type != "" ? "${path.module}/images/${var.type}.png" : null
avatar_hash = var.type != "" ? filesha256("${path.module}/images/${var.type}.png") : null
}
resource "gitlab_group_variable" "ci_variables" {
for_each = local.default_ci_variables
group = gitlab_group.group.id
key = each.key
value = each.value.value
description = each.value.description
protected = each.value.protected
masked = each.value.masked
environment_scope = each.value.environment_scope
}

View File

@ -1,3 +1,7 @@
output "example" { output "full_path" {
//value = some_resource.example value = gitlab_group.group.full_path
}
output "id" {
value = gitlab_group.group.id
} }

View File

@ -1,5 +1,8 @@
terraform { terraform {
required_providers { required_providers {
//Provider name gitlab = {
source = "gitlabhq/gitlab"
version = "17.3.1"
}
} }
} }

View File

@ -1,9 +1,45 @@
variable "parent_group" {
type = string
default = ""
description = "Parent group ID"
}
variable "name" { variable "name" {
type = string type = string
description = "name" description = "Group name"
} }
variable "description" { variable "description" {
type = string type = string
description = "description" description = "Group description"
}
variable "type" {
type = string
description = "Group type"
default = ""
validation {
condition = contains([
"",
"container",
"golang",
"typescript",
"cicd"
], var.type)
error_message = "Unsupported group type"
}
}
variable "ci_variables" {
type = map(object({
value = string
description = optional(string)
protected = optional(bool)
masked = optional(bool)
environment_scope = optional(string)
}))
description = "CI variables to be set for the group"
default = {}
} }