chore: defaults
This commit is contained in:
52
README.md
52
README.md
@@ -1 +1,51 @@
|
|||||||
# terraform module
|
## Requirements
|
||||||
|
|
||||||
|
| Name | Version |
|
||||||
|
|------|---------|
|
||||||
|
| <a name="requirement_gitlab"></a> [gitlab](#requirement\_gitlab) | 18.0.0 |
|
||||||
|
|
||||||
|
## Providers
|
||||||
|
|
||||||
|
| Name | Version |
|
||||||
|
|------|---------|
|
||||||
|
| <a name="provider_gitlab"></a> [gitlab](#provider\_gitlab) | 18.0.0 |
|
||||||
|
|
||||||
|
## Modules
|
||||||
|
|
||||||
|
No modules.
|
||||||
|
|
||||||
|
## Resources
|
||||||
|
|
||||||
|
| Name | Type |
|
||||||
|
|------|------|
|
||||||
|
| [gitlab_group.group](https://registry.terraform.io/providers/gitlabhq/gitlab/18.0.0/docs/resources/group) | resource |
|
||||||
|
| [gitlab_group_badge.badge](https://registry.terraform.io/providers/gitlabhq/gitlab/18.0.0/docs/resources/group_badge) | resource |
|
||||||
|
| [gitlab_group_label.label](https://registry.terraform.io/providers/gitlabhq/gitlab/18.0.0/docs/resources/group_label) | resource |
|
||||||
|
| [gitlab_group_ldap_link.link_gitlab_group_with_ad_group](https://registry.terraform.io/providers/gitlabhq/gitlab/18.0.0/docs/resources/group_ldap_link) | resource |
|
||||||
|
| [gitlab_group_variable.variable](https://registry.terraform.io/providers/gitlabhq/gitlab/18.0.0/docs/resources/group_variable) | resource |
|
||||||
|
| [gitlab_group.parent](https://registry.terraform.io/providers/gitlabhq/gitlab/18.0.0/docs/data-sources/group) | data source |
|
||||||
|
|
||||||
|
## Inputs
|
||||||
|
|
||||||
|
| Name | Description | Type | Default | Required |
|
||||||
|
|------|-------------|------|---------|:--------:|
|
||||||
|
| <a name="input_allowed_avatar_types_json"></a> [allowed\_avatar\_types\_json](#input\_allowed\_avatar\_types\_json) | Path to allowed avatar types json | `string` | `""` | no |
|
||||||
|
| <a name="input_avatar"></a> [avatar](#input\_avatar) | Type of the icon for the group (default: from type) | `string` | `""` | no |
|
||||||
|
| <a name="input_avatars_dir"></a> [avatars\_dir](#input\_avatars\_dir) | Avatars directory png files | `string` | `""` | no |
|
||||||
|
| <a name="input_badges"></a> [badges](#input\_badges) | n/a | <pre>map(object({<br/> link_url = string<br/> image_url = string<br/> }))</pre> | `{}` | no |
|
||||||
|
| <a name="input_default_branch"></a> [default\_branch](#input\_default\_branch) | The group's default branch | `string` | `"main"` | no |
|
||||||
|
| <a name="input_description"></a> [description](#input\_description) | Description of the gitlab group | `string` | n/a | yes |
|
||||||
|
| <a name="input_labels"></a> [labels](#input\_labels) | n/a | <pre>map(object({<br/> description = string<br/> color = string<br/> }))</pre> | `{}` | no |
|
||||||
|
| <a name="input_name"></a> [name](#input\_name) | Name of the gitlab group | `string` | n/a | yes |
|
||||||
|
| <a name="input_parent_group"></a> [parent\_group](#input\_parent\_group) | Gitlab parent group | `string` | n/a | yes |
|
||||||
|
| <a name="input_permissions"></a> [permissions](#input\_permissions) | Group permission mapping | <pre>map(object({<br/> permission = string<br/> }))</pre> | `{}` | no |
|
||||||
|
| <a name="input_variables"></a> [variables](#input\_variables) | n/a | <pre>map(object({<br/> value = string<br/> description = optional(string)<br/> protected = optional(bool)<br/> masked = optional(bool)<br/> environment_scope = optional(string)<br/> }))</pre> | `{}` | no |
|
||||||
|
| <a name="input_visibility"></a> [visibility](#input\_visibility) | The group's visibility | `string` | `"private"` | no |
|
||||||
|
|
||||||
|
## Outputs
|
||||||
|
|
||||||
|
| Name | Description |
|
||||||
|
|------|-------------|
|
||||||
|
| <a name="output_full_path"></a> [full\_path](#output\_full\_path) | Full path in gitlab for created group |
|
||||||
|
| <a name="output_group_name"></a> [group\_name](#output\_group\_name) | Name of created group |
|
||||||
|
| <a name="output_id"></a> [id](#output\_id) | ID of created group |
|
||||||
|
|||||||
5
data.tf
5
data.tf
@@ -1 +1,4 @@
|
|||||||
//Data
|
data "gitlab_group" "parent" {
|
||||||
|
count = var.parent_group != "" ? 1 : 0
|
||||||
|
full_path = var.parent_group
|
||||||
|
}
|
||||||
14
data/allowed_icon_types.json
Normal file
14
data/allowed_icon_types.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
[
|
||||||
|
"",
|
||||||
|
"ansible",
|
||||||
|
"archived",
|
||||||
|
"containers",
|
||||||
|
"devops",
|
||||||
|
"golang",
|
||||||
|
"gitlab",
|
||||||
|
"infrastructure",
|
||||||
|
"packer",
|
||||||
|
"python",
|
||||||
|
"terraform",
|
||||||
|
"typescript"
|
||||||
|
]
|
||||||
17
locals.tf
17
locals.tf
@@ -1,3 +1,18 @@
|
|||||||
//Locals
|
|
||||||
locals {
|
locals {
|
||||||
|
avatars_dir = var.avatars_dir == "" ? "${path.root}/images" : var.avatars_dir
|
||||||
|
|
||||||
|
allowed_avatar_types_json = var.allowed_avatar_types_json == "" ? "${path.root}/data/allowed_avatar_group_types.json" : var.allowed_avatar_types_json
|
||||||
|
allowed_avatar_types = jsondecode(file("${local.allowed_avatar_types_json}"))
|
||||||
|
|
||||||
|
# Define the allowed project types as a map
|
||||||
|
avatar = try(file("${local.avatars_dir}/${var.avatar}.png"), null) == null ? "${local.avatars_dir}/${var.avatar}.png" : null
|
||||||
|
|
||||||
|
permissions_list = {
|
||||||
|
for key, var in var.permissions : key => merge(
|
||||||
|
{
|
||||||
|
group = key,
|
||||||
|
permission = var.permission
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
52
main.tf
52
main.tf
@@ -1 +1,51 @@
|
|||||||
//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
|
||||||
|
default_branch = var.default_branch
|
||||||
|
avatar = local.avatar == null ? null : "${local.avatar}"
|
||||||
|
avatar_hash = local.avatar == null ? null : filesha256("${local.avatar}")
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "gitlab_group_label" "label" {
|
||||||
|
for_each = var.labels
|
||||||
|
|
||||||
|
group = gitlab_group.group.id
|
||||||
|
name = each.key
|
||||||
|
description = each.value.description
|
||||||
|
color = each.value.color
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "gitlab_group_badge" "badge" {
|
||||||
|
for_each = var.badges
|
||||||
|
|
||||||
|
group = gitlab_group.group.id
|
||||||
|
name = each.key
|
||||||
|
link_url = each.value.link_url
|
||||||
|
image_url = each.value.image_url
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "gitlab_group_variable" "variable" {
|
||||||
|
for_each = var.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
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "gitlab_group_ldap_link" "link_gitlab_group_with_ad_group" {
|
||||||
|
for_each = local.permissions_list
|
||||||
|
|
||||||
|
group = gitlab_group.group.full_path
|
||||||
|
cn = each.value.group
|
||||||
|
group_access = each.value.permission
|
||||||
|
ldap_provider = "ldapmain"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
15
output.tf
15
output.tf
@@ -1,3 +1,14 @@
|
|||||||
output "example" {
|
output "full_path" {
|
||||||
//value = some_resource.example
|
description = "Full path in gitlab for created group"
|
||||||
|
value = gitlab_group.group.full_path
|
||||||
|
}
|
||||||
|
|
||||||
|
output "id" {
|
||||||
|
description = "ID of created group"
|
||||||
|
value = gitlab_group.group.id
|
||||||
|
}
|
||||||
|
|
||||||
|
output "group_name" {
|
||||||
|
description = "Name of created group"
|
||||||
|
value = gitlab_group.group.name
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
terraform {
|
terraform {
|
||||||
required_providers {
|
required_providers {
|
||||||
//Provider name
|
gitlab = {
|
||||||
|
source = "gitlabhq/gitlab"
|
||||||
|
version = "18.0.0"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
100
variable.tf
100
variable.tf
@@ -1,9 +1,105 @@
|
|||||||
variable "name" {
|
variable "name" {
|
||||||
type = string
|
type = string
|
||||||
description = "name"
|
description = "Name of the gitlab group"
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "description" {
|
variable "description" {
|
||||||
type = string
|
type = string
|
||||||
description = "description"
|
description = "Description of the gitlab group"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "parent_group" {
|
||||||
|
type = string
|
||||||
|
description = "Gitlab parent group"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "visibility" {
|
||||||
|
type = string
|
||||||
|
default = "private"
|
||||||
|
description = "The group's visibility"
|
||||||
|
|
||||||
|
validation {
|
||||||
|
condition = contains([
|
||||||
|
"private",
|
||||||
|
"internal",
|
||||||
|
"public"
|
||||||
|
], var.visibility)
|
||||||
|
error_message = "Unsupported group visibility"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "default_branch" {
|
||||||
|
type = string
|
||||||
|
default = "main"
|
||||||
|
description = "The group's default branch"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "allowed_avatar_types_json" {
|
||||||
|
type = string
|
||||||
|
default = ""
|
||||||
|
description = "Path to allowed avatar types json"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
variable "avatar" {
|
||||||
|
type = string
|
||||||
|
description = "Type of the icon for the group (default: from type)"
|
||||||
|
default = ""
|
||||||
|
|
||||||
|
validation {
|
||||||
|
condition = contains(local.allowed_avatar_types, var.avatar)
|
||||||
|
error_message = "Unsupported group type"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "labels" {
|
||||||
|
type = map(object({
|
||||||
|
description = string
|
||||||
|
color = string
|
||||||
|
}))
|
||||||
|
default = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "badges" {
|
||||||
|
type = map(object({
|
||||||
|
link_url = string
|
||||||
|
image_url = string
|
||||||
|
}))
|
||||||
|
default = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "variables" {
|
||||||
|
type = map(object({
|
||||||
|
value = string
|
||||||
|
description = optional(string)
|
||||||
|
protected = optional(bool)
|
||||||
|
masked = optional(bool)
|
||||||
|
environment_scope = optional(string)
|
||||||
|
}))
|
||||||
|
default = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "permissions" {
|
||||||
|
type = map(object({
|
||||||
|
permission = string
|
||||||
|
}))
|
||||||
|
|
||||||
|
validation {
|
||||||
|
condition = alltrue([for k, v in var.permissions :
|
||||||
|
v.permission == "owner" ||
|
||||||
|
v.permission == "maintainer" ||
|
||||||
|
v.permission == "developer" ||
|
||||||
|
v.permission == "reporter" ||
|
||||||
|
v.permission == "guest"
|
||||||
|
])
|
||||||
|
error_message = "Each permission must be one of the following values: owner, maintainer, developer, reporter, guest"
|
||||||
|
}
|
||||||
|
description = "Group permission mapping"
|
||||||
|
default = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "avatars_dir" {
|
||||||
|
description = "Avatars directory png files"
|
||||||
|
type = string
|
||||||
|
default = ""
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user