Przejdź do treści

TERRAFORM - Utworzenie grupy repozytoriów w gitlab

Jak utworzyć grupę pl.rachuna-net/cicd przy użyciu Terraform na potrzeby projektu cicd?

Dlaczego?

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

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

📄 Plik: pl.rachuna-net/grp_cicd.tf

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

    name         = "cicd"
    description  = "Gitlab CI/CD"
    parent_group = local.parent_name
    visibility   = "public"
    icon_type    = "gitlab"
}

# module "cicd" {
#     source = "./cicd/"
# }
Utworzony commit commit

Weryfikacja Terraform Plan

Wynik 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.group_cicd.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.group_cicd/images/gitlab.png"
      + avatar_hash                        = "d03595286956bb3c8f1a3db87dbcd8a5528dc97838fe8b9909b9d86f85f64d95"
      + avatar_url                         = (known after apply)
      + default_branch                     = "main"
      + default_branch_protection          = (known after apply)
      + description                        = "Gitlab CI/CD"
      + 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                               = "cicd"
      + parent_id                          = 103953825
      + path                               = "cicd"
      + 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)
    }

Z logu wynika, że Terraform utworzy nową grupę cicd. Należy zatwierdzić zmianę i wdrożyć ją do main poprzez Merge Request (MR).

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