Przejdź do treści

Tworzymy grupę repozytoriów za pomocą terraform

Dziś pokażę, jak utworzyć grupę pl.rachuna-net/infrastructure/packer przy użyciu Terraform na potrzeby projektu Packer.

Czemu chcesz tworzyć grupę za pomocą terraform?

Zarządzanie infrastrukturą jako kodem (IaC) pozwala na automatyzację i standaryzację, wersjonowanie i powtarzalność konfiguracji, co ułatwia utrzymanie i rozwój projektów.

Definiowanie grupy w Terraform

Tworzymy plik definiujący grupę w repozytorium:
🔗 Lokalizacja: GitLab: pl.rachuna-net/infrastructure/terraform/gitlab

📄 Plik: pl.rachuna-net/infrastructure/grp_packer.tf

module "group_packer" {
    source = "git@gitlab.com:pl.rachuna-net/infrastructure/terraform/modules/gitlab-group.git?ref=v1.1.1"

    name         = "packer"
    description  = "Virtual machine templates for Packer"
    parent_group = local.parent_name
    visibility   = "public"
    icon_type    = "packer"
}

# Odkomentuj po utworzeniu modułu Packer i dodaniu pierwszego pliku w tym katalogu
# module "packer" {
#     source = "./packer/"
# }
Zrobiona przez nas zmiana commit

Weryfikacja Terraform Plan

Po zapisaniu konfiguracji uruchamiamy terraform plan, aby sprawdzić, jakie zmiany zostaną wprowadzone:

(...)
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  + create
Terraform will perform the following actions:
  # module.pl_rachuna-net.module.infrastructure.module.group_packer.gitlab_group.group will be created
  + resource "gitlab_group" "group" {
      + allowed_email_domains_list         = (known after apply)
      + auto_devops_enabled                = (known after apply)
      + avatar                             = ".terraform/modules/pl_rachuna-net.infrastructure.group_packer/images/packer.png"
      + avatar_hash                        = "7b6d29da98428d8917da19d0033ad7281cc956ade0b05867726f3df6dc8bcab7"
      + avatar_url                         = (known after apply)
      + default_branch                     = "main"
      + default_branch_protection          = (known after apply)
      + description                        = "Virtual machine templates for Packer"
      + emails_enabled                     = (known after apply)
      + extra_shared_runners_minutes_limit = (known after apply)
      + full_name                          = (known after apply)
      + full_path                          = (known after apply)
      + id                                 = (known after apply)
      + lfs_enabled                        = (known after apply)
      + mentions_disabled                  = (known after apply)
      + name                               = "packer"
      + parent_id                          = 102204432
      + path                               = "packer"
      + permanently_remove_on_delete       = false
      + prevent_forking_outside_group      = (known after apply)
      + project_creation_level             = (known after apply)
      + request_access_enabled             = (known after apply)
      + require_two_factor_authentication  = (known after apply)
      + runners_token                      = (sensitive value)
      + share_with_group_lock              = (known after apply)
      + shared_runners_minutes_limit       = (known after apply)
      + shared_runners_setting             = (known after apply)
      + subgroup_creation_level            = (known after apply)
      + two_factor_grace_period            = (known after apply)
      + visibility_level                   = "public"
      + web_url                            = (known after apply)
      + wiki_access_level                  = (known after apply)
      + default_branch_protection_defaults (known after apply)
      + push_rules (known after apply)
    }
Plan: 1 to add, 0 to change, 0 to destroy.

Z powyższego logu widzimy, że Terraform utworzy nową grupę packer. Jeśli wszystko wygląda poprawnie, możemy zatwierdzić zmianę i wdrożyć ją do main poprzez Merge Request (MR).

🚀 Gotowe! Grupa repozytoriów została utworzona przy użyciu Terraform. 🎉