GitLab Terraform Provider

repository·main·Indexed 19 days ago

https://github.com/gitlabhq/terraform-provider-gitlab

The GitLab Terraform Provider enables Infrastructure as Code (IaC) workflows to manage GitLab resources such as projects, groups, and users using Terraform configuration files. It provides various data sources to retrieve metadata for GitLab applications, artifact files, repository branches, Kubernetes cluster agents, compliance frameworks, and group-level access tokens and hooks.

Tokens
195.1K
Snippets
496
Records
715
Agent score
64%

What's inside terraform-provider-gitlab

  1. Manage the GitLab group Docker dependency proxy

    main

    The gitlab_group_dependency_proxy resource allows you to manage the Docker dependency proxy at the group level.

    Important Constraints:

    • Only one dependency proxy can exist per group; attempting to manage more than one will cause conflicts.
    • This resource is specifically for the group Docker dependency proxy. If you need to manage the project-level package dependency proxy, use the gitlab_project_package_registry_proxy resource instead.
    • The secret field cannot be retrieved via import and must be provided in your Terraform configuration even after an import.
    resource "gitlab_group_dependency_proxy" "foo" {
      group = "1234"
    
      enabled  = true
      identity = "newidentity"
      secret   = "somesecret"
    }
  2. Retrieve multiple groups with gitlab_groups data source

    main

    The gitlab_groups data source allows you to retrieve details for multiple GitLab groups based on optional filter criteria.

    Important Notes:

    • Some attributes may not be returned depending on your administrator privileges.
    • Certain configuration options require administrator privileges.
    • This data source maps to the GitLab REST API GET /groups endpoint.
    data "gitlab_groups" "example" {
      sort     = "desc"
      order_by = "name"
    }
    
    data "gitlab_groups" "example-two" {
      search = "GitLab"
    }
  3. Manage files in a GitLab repository with gitlab_repository_file

    main

    The gitlab_repository_file resource allows you to manage the lifecycle of a file within a GitLab repository, including creating, updating, and deleting files via commits.

    Important Implementation Details

    • Concurrency: GitLab cannot handle concurrent calls to the repository files API for the same project. To prevent errors, this resource queues every call to the repository files API globally, which may increase Terraform execution time.
    • Retries: The provider performs retries if a refresh is required because another application changed the repository simultaneously.
    • Timeouts: The default timeout for Create, Update, and Delete operations is one minute. You can customize these in the timeouts block.
    resource "gitlab_repository_file" "this" {
      project        = gitlab_project.this.id
      file_path      = "meow.txt"
      branch         = "main"
      encoding       = "base64"
      content        = base64encode("Meow goes the cat")
      author_email   = "terraform@example.com"
      author_name    = "Terraform"
      commit_message = "feature: add meow file"
    }
  4. Manage a GitLab project push mirror

    main

    The gitlab_project_push_mirror resource manages the lifecycle of a project mirror used for pushing changes to a remote repository.

    Warning: By default, the provider sets keep_divergent_refs to True. If you manually set keep_divergent_refs to False, GitLab mirroring will remove branches in the target repository that are not present in the source. This can lead to unexpected branch deletions.

    Note that for pull mirroring, you should use the gitlab_project_pull_mirror resource instead.

    ```terraform
    resource "gitlab_project_push_mirror" "foo" {
      project = "1"
      url     = "https://username:password@github.com/org/repository.git"
    }
    ```埋
  5. Manage GitLab project hooks with gitlab_project_hook

    main

    The gitlab_project_hook resource manages the lifecycle of webhooks for a specific GitLab project. Webhooks allow you to trigger external services when specific events occur within a project (e.g., push events, merge request events, or pipeline events).

    Important Note: The push_events attribute defaults to true. If you want to disable push event notifications, you must explicitly set push_events = false.

    resource "gitlab_project_hook" "example" {
      project               = "example/hooked"
      url                   = "https://example.com/hook/example"
      name                  = "example"
      description           = "Example hook"
      merge_requests_events = true
    
      # Set to false to avoid default true value
      push_events = false
    }
  6. Manage GitLab group epic boards with gitlab_group_epic_board

    main

    The gitlab_group_epic_board resource manages the lifecycle of an epic board within a GitLab group.

    Note: Creating multiple epic boards on a single group requires a GitLab Premium or higher license.

    Upstream API: GitLab REST API docs

    resource "gitlab_group_epic_board" "epic_board" {
      name  = "epic board 6"
      group = gitlab_group.example.path
      lists {
        label_id = gitlab_group_label.label_1.label_id
      }
    }
  7. Manage GitLab groups with gitlab_group

    main

    The gitlab_group resource manages the lifecycle of a GitLab group.

    Important Note for GitLab.com users: You cannot use this resource to create a top-level group. To manage a top-level group with Terraform, you must first create it via the GitLab UI and then import it into your Terraform configuration.

    resource "gitlab_group" "example" {
      name        = "example"
      path        = "example"
      description = "An example group"
    }
  8. Manage user project membership with gitlab_project_membership

    main

    The gitlab_project_membership resource manages the lifecycle of an individual user's membership within a specific GitLab project.

    Note: If you need to grant membership to an entire group rather than an individual user, use the gitlab_project_share_group resource instead.

    resource "gitlab_project_membership" "test" {
      project      = "12345"
      user_id      = 1337
      access_level = "guest"
    }
  9. Manage GitLab project pull mirroring with gitlab_project_pull_mirror

    main

    The gitlab_project_pull_mirror resource allows you to configure and manage pull mirroring for GitLab projects. It uses a dedicated API endpoint to ensure reliable configuration after a project has been created.

    When configuring a mirror, you can specify basic authentication via auth_user and auth_password rather than including credentials in the url for better security and idempotency. If you omit optional settings, GitLab will apply its default behaviors.

    resource "gitlab_project_pull_mirror" "github" {
      project       = gitlab_project.example.id
      url           = "https://github.com/example/repo.git"
      auth_user     = "github-username"
      auth_password = var.github_token
    }
  10. Manage GitLab application settings with gitlab_application_settings

    main

    The gitlab_application_settings resource allows you to manage global GitLab application settings.

    Important Considerations:

    • Experimental Status: This is an experimental resource that may not behave like standard Terraform resources.
    • Single Instance: All instances of this resource use the same ID: gitlab.
    • No Destroy Logic: The resource does not implement destroy logic (it is a no-op during terraform destroy).
    • No Reversion: It is not possible to revert to previous settings using this resource.
    • Permissions: Requires administrative privileges on GitLab.
    • Upstream API: Based on the GitLab REST API settings.
    resource "gitlab_application_settings" "this" {
      default_branch_name = "main"
    }