diff --git a/data.tf b/data.tf index 0ad8665..38aec76 100644 --- a/data.tf +++ b/data.tf @@ -1 +1,4 @@ -//Data +data "gitlab_group" "parent" { + count = var.parent_group != "" ? 1 : 0 + full_path = var.parent_group +} diff --git a/images/golang.png b/images/golang.png new file mode 100644 index 0000000..5eee2c9 Binary files /dev/null and b/images/golang.png differ diff --git a/images/typescript.png b/images/typescript.png new file mode 100644 index 0000000..a855ee8 Binary files /dev/null and b/images/typescript.png differ diff --git a/locals.tf b/locals.tf index 69083a6..ca93499 100644 --- a/locals.tf +++ b/locals.tf @@ -1,3 +1,13 @@ -//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 + ) + } } diff --git a/main.tf b/main.tf index 882e72a..f4e9d1a 100644 --- a/main.tf +++ b/main.tf @@ -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 +} + diff --git a/output.tf b/output.tf index c608d5f..21085a9 100644 --- a/output.tf +++ b/output.tf @@ -1,3 +1,7 @@ -output "example" { - //value = some_resource.example +output "full_path" { + value = gitlab_group.group.full_path +} + +output "id" { + value = gitlab_group.group.id } diff --git a/provider.tf b/provider.tf index f21e096..ca1e214 100644 --- a/provider.tf +++ b/provider.tf @@ -1,5 +1,8 @@ terraform { required_providers { - //Provider name + gitlab = { + source = "gitlabhq/gitlab" + version = "17.3.1" + } } } diff --git a/variable.tf b/variable.tf index f8598a8..f93ba2d 100644 --- a/variable.tf +++ b/variable.tf @@ -1,9 +1,45 @@ + +variable "parent_group" { + type = string + default = "" + description = "Parent group ID" +} + variable "name" { type = string - description = "name" + description = "Group name" } variable "description" { 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 = {} }