### Create a GitLab Agent, token, and install Helm Chart Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/resources/cluster_agent_token.md This example demonstrates a complete workflow: creating a GitLab Agent, generating a token for it, and then installing the `gitlab-agent` Helm Chart using the generated token. This is useful for setting up a new agent and its associated deployment. ```terraform data "gitlab_project" "this" { path_with_namespace = "my-org/example" } resource "gitlab_cluster_agent" "this" { project = data.gitlab_project.this.id name = "my-agent" } resource "gitlab_cluster_agent_token" "this" { project = data.gitlab_project.this.id agent_id = gitlab_cluster_agent.this.agent_id name = "my-agent-token" description = "Token for the my-agent used with `gitlab-agent` Helm Chart" } resource "helm_release" "gitlab_agent" { name = "gitlab-agent" namespace = "gitlab-agent" create_namespace = true repository = "https://charts.gitlab.io" chart = "gitlab-agent" version = "1.2.0" set { name = "config.token" value = gitlab_cluster_agent_token.this.token } } ``` -------------------------------- ### Start GitLab Container for Tests Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/CONTRIBUTING.md Use this command to start a local GitLab container for running acceptance tests. Ensure docker-compose is installed. ```sh make testacc-up ``` -------------------------------- ### Example Datasource Configuration Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/development/CreatingANewDatasource.md Provide an example configuration for the datasource in HCL format. This file should be placed in the `examples/datasources/` directory. ```hcl data "gitlab_cluster_agent" "example" { project = "12345" agent_id = 1 } ``` -------------------------------- ### Example Usage Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/resources/user_avatar.md This example shows how to create a personal access token and then use it to set a user avatar. The avatar_hash is recommended for tracking changes. ```terraform resource "gitlab_personal_access_token" "example" { user_id = "25" name = "Example personal access token" expires_at = "2020-03-14" scopes = ["api"] } resource "gitlab_user_avatar" "example" { user_id = gitlab_personal_access_token.example.user_id token = gitlab_personal_access_token.example.token avatar = "${path.module}/avatar.png" avatar_hash = filesha256("${path.module}/avatar.png") } ``` -------------------------------- ### Import Resource Example (Bash) Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/development/CreatingANewResource.md Provide an example of how to import an existing GitLab resource into Terraform state using its ID. This script is placed in an `import.sh` file within the resource's example directory. ```bash # Gitlab applications can be imported with their id, e.g. terraform import gitlab_application.example "1" ``` -------------------------------- ### Start Local GitLab Container for Acceptance Tests Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/AGENTS.md Starts a local GitLab container for running acceptance tests. Ensure `GITLAB_TOKEN` is unset. Use `SERVICE=gitlab-ee` if `Gitlab-license.txt` is present. ```bash unset GITLAB_TOKEN && make testacc-up ``` ```bash unset GITLAB_TOKEN && SERVICE=gitlab-ee make testacc-up ``` -------------------------------- ### Output Example: Get Token Names Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/data-sources/group_service_account_access_tokens.md This example demonstrates how to extract and output the names of all retrieved access tokens from the `gitlab_group_service_account_access_tokens` data source. ```terraform output "token_names" { value = [for token in data.gitlab_group_service_account_access_tokens.example.access_tokens : token.name] } ``` -------------------------------- ### Example Usage: Manage GPG Key for the Current User Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/resources/user_gpgkey.md This example shows how to manage a GPG key for the currently authenticated user. No specific user ID is required, simplifying the process for managing your own GPG keys. ```terraform # Manages a GPG key for the current user resource "gitlab_user_gpgkey" "example_user" { key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n...\n-----END PGP PUBLIC KEY BLOCK-----" } ``` -------------------------------- ### Start GitLab Enterprise Edition Container Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/AGENTS.md Starts a GitLab Enterprise Edition container for testing, requires `Gitlab-license.txt` in the repository root. ```bash make testacc-up SERVICE=gitlab-ee ``` -------------------------------- ### Example Usage of gitlab_project_integration_harbor Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/resources/project_integration_harbor.md This example demonstrates how to configure a Harbor integration for a GitLab project. It requires a `gitlab_project` resource to be defined first, and then uses its ID to set up the Harbor integration with the specified URL and project name. ```terraform resource "gitlab_project" "awesome_project" { name = "awesome_project" description = "My awesome project." visibility_level = "public" } resource "gitlab_project_integration_harbor" "harbor" { project = gitlab_project.awesome_project.id url = "http://harbor.example.com" project_name = "my_project_name" } ``` -------------------------------- ### Build the GitLab Terraform Provider Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/AGENTS.md Compiles the provider binary and installs it to the `$GOPATH/bin` directory. ```bash make build ``` -------------------------------- ### Custom Headers Example Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/resources/project_hook.md Example of how to use custom headers with a project hook. ```APIDOC ## gitlab_project_hook with Custom Headers ### Description This example demonstrates how to configure custom headers for a project hook. ### Method Not applicable (Terraform resource) ### Endpoint Not applicable (Terraform resource) ### Parameters #### Schema (relevant fields) - **project** (string) - Required - The name or ID of the project. - **url** (string) - Required - The URL of the webhook. - **custom_headers** (list of objects) - Optional - Custom headers to send with the webhook request. - **key** (string) - Required - The key of the header. - **value** (string) - Required - The value of the header. ### Request Example ```terraform resource "gitlab_project_hook" "custom_headers" { project = "example/hooked" url = "https://example.com/hook/example" merge_requests_events = true custom_headers = [ { key = "X-Custom-Header" value = "example" }, { key = "X-Custom-Header-Second" value = "example-second" } ] } ``` ``` -------------------------------- ### Example Usage Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/data-sources/group_service_account_access_tokens.md This example shows how to retrieve all access tokens for a group service account using the `gitlab_group_service_account_access_tokens` data source. It first retrieves the group ID and then uses it along with the service account ID to fetch the tokens. ```terraform data "gitlab_group" "example" { id = "foo/bar/baz" } # List all access tokens for a group service account data "gitlab_group_service_account_access_tokens" "example" { group = data.gitlab_group.example.id service_account_id = 123 } ``` -------------------------------- ### Start GitLab EE Container for Tests Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/CONTRIBUTING.md Start a GitLab Enterprise Edition container for testing EE-specific features. Requires a valid Gitlab-license.txt. ```sh make testacc-up SERVICE=gitlab-ee ``` -------------------------------- ### Basic Example Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/data-sources/project_service_account.md Use this snippet to retrieve a GitLab service account by its ID and project. ```terraform data "gitlab_project" "example" { id = "foo/bar" } # Basic example data "gitlab_project_service_account" "example" { service_account_id = 1 project = data.gitlab_project.example.id } ``` -------------------------------- ### Example Usage of gitlab_project_integration_mattermost Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/resources/project_integration_mattermost.md This example demonstrates how to configure a Mattermost integration for a GitLab project. It requires a project to be defined and then sets up the Mattermost integration with a webhook URL and specific event notifications. ```terraform resource "gitlab_project" "awesome_project" { name = "awesome_project" description = "My awesome project." visibility_level = "public" } resource "gitlab_project_integration_mattermost" "mattermost" { project = gitlab_project.awesome_project.id webhook = "https://webhook.com" username = "myuser" push_events = true push_channel = "push_chan" } ``` -------------------------------- ### Resource Configuration Example (HCL) Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/development/CreatingANewResource.md Define an example Terraform HCL configuration for the `gitlab_application` resource. This file, typically named `resource.tf`, demonstrates how to set resource attributes. ```hcl resource "gitlab_application" "oidc" { confidential = true scopes = ["openid"] name = "company_oidc" redirect_url = "https://mycompany.com" } ``` -------------------------------- ### Example Usage of gitlab_project_hooks Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/data-sources/project_hooks.md This example demonstrates how to use the `gitlab_project_hooks` data source to retrieve hook details for a specific project. It first fetches the project using the `gitlab_project` data source and then uses its ID to query for project hooks. ```terraform data "gitlab_project" "example" { id = "foo/bar/baz" } data "gitlab_project_hooks" "examples" { project = data.gitlab_project.example.id } ``` -------------------------------- ### Example Usage: Manage GPG Key for a Specific User Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/resources/user_gpgkey.md This example demonstrates how to manage a GPG key for a specific user by first retrieving the user's ID using the `gitlab_user` data source and then assigning the GPG key using the `gitlab_user_gpgkey` resource. An admin token is required if `user_id` is specified. ```terraform data "gitlab_user" "example" { username = "example-user" } # Manages a GPG key for the specified user. An admin token is required if `user_id` is specified. resource "gitlab_user_gpgkey" "example" { user_id = data.gitlab_user.example.id key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n...\n-----END PGP PUBLIC KEY BLOCK-----" } ``` -------------------------------- ### Install Provider Locally for System-wide Use Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/CONTRIBUTING.md Install the locally built provider to the system for use in any Terraform configuration. Use the 'make local' command, optionally specifying TERRAFORM_PLATFORM_DIR for specific platforms or TERRAFORM_PLUGIN_DIR for custom plugin directories. ```sh # Default: suitable for macOS make local # Set the terraform platform directory # e.g. for linux amd64: make local TERRAFORM_PLATFORM_DIR=linux_amd64 # Set the terraform plugin dir, see https://www.terraform.io/cli/config/config-file#implied-local-mirror-directories # e.g. for Windows make local TERRAFORM_PLUGIN_DIR=%APPDATA%/terraform.d/plugins ``` -------------------------------- ### Example Usage Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/data-sources/instance_service_account.md Use this data source to retrieve information about a specific service account by its ID. ```terraform data "gitlab_instance_service_account" "example" { service_account_id = "123" } ``` -------------------------------- ### Output Example: Get Active Tokens Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/data-sources/group_service_account_access_tokens.md This example shows how to filter and output only the active access tokens from the list retrieved by the `gitlab_group_service_account_access_tokens` data source. ```terraform output "active_tokens" { value = [for token in data.gitlab_group_service_account_access_tokens.example.access_tokens : token if token.active] } ``` -------------------------------- ### Create a Project and Configure External Wiki Integration Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/resources/project_integration_external_wiki.md This example demonstrates how to create a new GitLab project and then configure an external wiki integration for it. Ensure the gitlab_project resource is defined before the integration resource. ```terraform resource "gitlab_project" "awesome_project" { name = "awesome_project" description = "My awesome project." visibility_level = "public" } resource "gitlab_project_integration_external_wiki" "wiki" { project = gitlab_project.awesome_project.id external_wiki_url = "https://MyAwesomeExternalWikiURL.com" } ``` -------------------------------- ### Get gitlab_pipeline_schedule Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/data-sources/pipeline_schedule.md Example of how to retrieve a pipeline schedule using its project and schedule ID. ```terraform data "gitlab_pipeline_schedule" "example" { project = "12345" pipeline_schedule_id = 1 } ``` -------------------------------- ### Create a new project, add a policy, and attach it to groups Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/resources/group_security_policy_attachment.md This example demonstrates creating a new project for security policies, adding a policy file to it, and then attaching this project to a group. It uses `gitlab_project` to create the project and `gitlab_repository_file` to manage the policy content. ```terraform resource "gitlab_project" "my-policy-project" { name = "security-policy-project" } resource "gitlab_repository_file" "policy-yml" { project = gitlab_project.my-policy-project.id file_path = ".gitlab/security-policies/my-policy.yml" branch = "master" encoding = "text" content = <<-EOT --- approval_policy: - name: test description: test enabled: true rules: - type: any_merge_request branch_type: protected commits: any approval_settings: block_branch_modification: true prevent_pushing_and_force_pushing: true prevent_approval_by_author: true prevent_approval_by_commit_author: true remove_approvals_with_new_commit: true require_password_to_approve: false fallback_behavior: fail: closed policy_scope: compliance_frameworks: - id: 1010101 - id: 0101010 actions: - type: send_bot_message enabled: true EOT } # Multiple policies can be attached to a single project by repeating this resource or using a `for_each` resource "gitlab_group_security_policy_attachment" "my-policy" { group = 1234 policy_project = gitlab_project.my-policy-project.id } ``` -------------------------------- ### Create a Project and Configure Pipeline Emails Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/resources/project_integration_pipelines_email.md This example shows how to create a new GitLab project and then configure the Pipeline Emails Service for it. Ensure the `gitlab_project` resource is defined before this one. ```terraform resource "gitlab_project" "awesome_project" { name = "awesome_project" description = "My awesome project." visibility_level = "public" } resource "gitlab_project_integration_pipelines_email" "email" { project = gitlab_project.awesome_project.id recipients = ["gitlab@user.create"] notify_only_broken_pipelines = true branches_to_be_notified = "all" } ``` -------------------------------- ### Terraform Configuration for Local Provider Source Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/CONTRIBUTING.md Example Terraform configuration block to specify a local provider source, typically used after installing a locally built provider. ```hcl terraform { required_providers { gitlab = { version = "99.99.99" source = "gitlab.local/x/gitlab" } } } ``` -------------------------------- ### Import a gitlab_instance_service_account resource Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/resources/instance_service_account.md This example shows how to import an existing gitlab_instance_service_account resource into Terraform state. The import requires the service account's ID. This feature is available starting in Terraform v1.5.0. ```terraform import { to = gitlab_instance_service_account.example id = "see CLI command below for ID" } ``` ```shell # You can import a group service account using `terraform import `. The # `id` is the id of the service account terraform import gitlab_instance_service_account.example example ``` -------------------------------- ### Allow a group using gitlab_project_job_token_scope Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/resources/project_job_token_scope.md Use `for_each` to manage multiple group IDs in the CI/CD job token inbound allowlist. This example uses a `data` source to get the project ID and a `local` variable for the target group IDs. ```terraform resource "gitlab_project_job_token_scope" "allowed_group" { for_each = toset(local.allowed_group_ids) project = data.gitlab_project.deployment_project.id target_group_id = each.key } ``` -------------------------------- ### Allow multiple projects using gitlab_project_job_token_scope Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/resources/project_job_token_scope.md Use `for_each` to manage multiple project IDs in the CI/CD job token inbound allowlist. This example uses a `data` source to get the project ID and a `local` variable for the target project IDs. ```terraform locals { allowed_project_ids = [123, 456, 789] allowed_group_ids = [123, 456, 789] } data "gitlab_project" "deployment_project" { name = "example-project" } resource "gitlab_project_job_token_scope" "allowed_project" { for_each = toset(local.allowed_project_ids) project = data.gitlab_project.deployment_project.id target_project_id = each.key } ``` -------------------------------- ### Example Usage of gitlab_group_service_account Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/data-sources/group_service_account.md Demonstrates how to use the gitlab_group_service_account data source to retrieve service account information. It first fetches group details using the gitlab_group data source and then uses the service account ID and group ID to get the service account. ```terraform data "gitlab_group" "example" { id = "foo/bar/baz" } # Basic example data "gitlab_group_service_account" "example" { service_account_id = 1 group = data.gitlab_group.example.id } ``` -------------------------------- ### URL Variables Example Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/resources/project_hook.md Example of how to use URL variables with a project hook. ```APIDOC ## gitlab_project_hook with URL Variables ### Description This example shows how to configure URL variables for a project hook. ### Method Not applicable (Terraform resource) ### Endpoint Not applicable (Terraform resource) ### Parameters #### Schema (relevant fields) - **project** (string) - Required - The name or ID of the project. - **url** (string) - Required - The URL of the webhook. - **url_variables** (list of objects) - Optional - URL variables to send with the webhook request. - **key** (string) - Required - The key of the URL variable. - **value** (string) - Required - The value of the URL variable. ### Request Example ```terraform resource "gitlab_project_hook" "url_variables" { project = "example/hooked" url = "https://example.com/hook/example?token=secret" merge_requests_events = true url_variables = [ { key = "hidden" value = "token=secret" } ] } ``` ``` -------------------------------- ### Create a new policy project, add a policy, and attach it Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/resources/project_security_policy_attachment.md This example demonstrates creating a new GitLab project to host security policies, adding a YAML policy file to it using `gitlab_repository_file`, and then attaching this new policy project to another project. This approach ensures all policy options are available via Terraform. ```terraform resource "gitlab_project" "my-policy-project" { name = "security-policy-project" } resource "gitlab_repository_file" "policy-yml" { project = gitlab_project.my-policy-project.id file_path = ".gitlab/security-policies/my-policy.yml" branch = "master" encoding = "text" content = <<-EOT --- approval_policy: - name: test description: test enabled: true rules: - type: any_merge_request branch_type: protected commits: any approval_settings: block_branch_modification: true prevent_pushing_and_force_pushing: true prevent_approval_by_author: true prevent_approval_by_commit_author: true remove_approvals_with_new_commit: true require_password_to_approve: false fallback_behavior: fail: closed actions: - type: send_bot_message enabled: true EOT } # Multiple policies can be attached to a single project by repeating this resource or using a `for_each` resource "gitlab_project_security_policy_attachment" "my-policy" { project = 1234 policy_project = gitlab_project.my-policy-project.id } ``` -------------------------------- ### Example using manual certificate and key Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/resources/pages_domain.md Use this snippet to configure a custom GitLab Pages domain with your own SSL certificate and private key. The `key` and `certificate` arguments accept file paths to your PEM-encoded files. ```terraform resource "gitlab_pages_domain" "this" { project = 123 domain = "example.com" key = file("${path.module}/key.pem") certificate = file("${path.module}/cert.pem") } ``` -------------------------------- ### Project Deploy Key Example Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/resources/deploy_key.md Use this resource to manage a project deploy key. It requires the project name, a title, and the public SSH key. ```terraform resource "gitlab_deploy_key" "example" { project = "example/deploying" title = "Example deploy key" key = "ssh-ed25519 AAAA..." } ``` ```terraform resource "gitlab_deploy_key" "example_expires" { project = "example/deploying" title = "Example deploy key" key = "ssh-ed25519 AAAA..." expires_at = "2025-01-21T00:00:00Z" } ``` -------------------------------- ### Use Test Helper for Resource Creation Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/AGENTS.md Illustrates using the `testutil` helper function to create test resources, which is preferred over including them directly in test configurations. ```go import "gitlab.com/gitlab-org/terraform-provider-gitlab/internal/provider/testutil" testProject := testutil.CreateProject(t) // Use testProject.ID in your test configuration ``` -------------------------------- ### Basic gitlab_project_push_mirror Usage Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/resources/project_push_mirror.md Example of how to configure a basic project push mirror. Ensure the project ID and repository URL are correctly specified. Sensitive information in the URL may require a replace on the first apply. ```terraform resource "gitlab_project_push_mirror" "foo" { project = "1" url = "https://username:password@github.com/org/repository.git" } ``` -------------------------------- ### Configure Function for Resources (Go) Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/Migration.md This code snippet shows the standard content for the Configure function in Framework resources. The client field should be set directly and not obfuscated. ```go if req.ProviderData == nil { return } resourceData := req.ProviderData.(*GitLabResourceData) r.client = resourceData.Client ``` -------------------------------- ### Output detailed information about each token Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/data-sources/project_access_tokens.md This example demonstrates how to iterate through all retrieved project access tokens and output detailed information for each one. ```terraform output "token_details" { description = "Detailed information about each access token" value = [ for token in data.gitlab_project_access_tokens.all_tokens.access_tokens : { id = token.id name = token.name description = token.description scopes = token.scopes active = token.active revoked = token.revoked created_at = token.created_at expires_at = token.expires_at access_level = token.access_level user_id = token.user_id last_used_at = token.last_used_at } ] } ``` -------------------------------- ### Create a Gitlab Project and Configure Redmine Integration Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/resources/project_integration_redmine.md This example demonstrates how to create a GitLab project and then configure a Redmine integration for it. Ensure Redmine is accessible and configured correctly. ```terraform resource "gitlab_project" "awesome_project" { name = "awesome_project" description = "My awesome project." visibility_level = "public" } resource "gitlab_project_integration_redmine" "redmine" { project = gitlab_project.awesome_project.id new_issue_url = "https://redmine.example.com/issue" project_url = "https://redmine.example.com/project" issues_url = "https://redmine.example.com/issue/:id" } ``` -------------------------------- ### GitLab Branch Protection EE Admin Push Access Example Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/resources/branch_protection.md This example configures branch protection for GitLab Enterprise Edition, specifically granting 'admin' access level for pushing and 'maintainer' for merging and unprotecting. ```terraform resource "gitlab_branch_protection" "admin_push" { project = "12345" branch = "admin-protected" allowed_to_push = [ { access_level = "admin" } ] allowed_to_merge = [ { access_level = "maintainer" } ] allowed_to_unprotect = [ { access_level = "maintainer" } ] } ``` -------------------------------- ### Example Usage Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/data-sources/pipeline_schedules.md Use the `gitlab_pipeline_schedules` data source to retrieve information about pipeline schedules for a specific project. You must provide the project's name or ID. ```terraform data "gitlab_pipeline_schedules" "example" { project = "12345" } ``` -------------------------------- ### GitLab Branch Protection EE Example Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/resources/branch_protection.md This example demonstrates branch protection configuration for GitLab Enterprise Edition, including code owner approval and detailed access controls for push, merge, and unprotect actions. ```terraform resource "gitlab_branch_protection" "ee_branch" { project = "12345" branch = "BranchProtected" allow_force_push = true code_owner_approval_required = true allowed_to_push = [ { user_id = 5 }, { user_id = 521 }, { access_level = "no one" } ] allowed_to_merge = [ { user_id = 15 }, { user_id = 37 }, { access_level = "maintainer" } ] allowed_to_unprotect = [ { user_id = 15 }, { group_id = 42 }, { access_level = "maintainer" } ] } ``` -------------------------------- ### Register Resource with Provider (Go) Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/development/CreatingANewResource.md Implement the `init` function to register the new resource with the provider using a helper function. This allows the resource to be used in Terraform configurations. ```go func init() { registerResource(NewGitLabApplicationResource) } // NewGitLabApplicationResource is a helper function to simplify the provider implementation. func NewGitLabApplicationResource() resource.Resource { return &gitlabApplicationResource{} } ``` -------------------------------- ### Example Usage of gitlab_project_integration_custom_issue_tracker Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/resources/project_integration_custom_issue_tracker.md This example demonstrates how to configure a custom issue tracker integration for a GitLab project using Terraform. It first creates a project and then associates a custom issue tracker with it, specifying the URLs for the project and issues. ```terraform resource "gitlab_project" "awesome_project" { name = "awesome_project" description = "My awesome project." visibility_level = "public" } resource "gitlab_project_integration_custom_issue_tracker" "tracker" { project = gitlab_project.awesome_project.id project_url = "https://customtracker.com/issues" issues_url = "https://customtracker.com/TEST-:id" } ``` -------------------------------- ### Example Usage Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/data-sources/group_access_tokens.md Use the `gitlab_group_access_tokens` data source to fetch all access tokens for a specified group. Provide the group's name or ID. ```terraform data "gitlab_group_access_tokens" "access_tokens" { group = "my/example/group" } ``` -------------------------------- ### Example Usage of gitlab_project_environments Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/data-sources/project_environments.md Demonstrates how to use the gitlab_project_environments data source to retrieve environments for a project. It first defines a project resource and then uses its `path_with_namespace` attribute to specify the project for the data source. You can also use the project ID directly. ```terraform resource "gitlab_project" "this" { name = "example" initialize_with_readme = true } data "gitlab_project_environments" "this" { project = gitlab_project.this.path_with_namespace # Can also use project id } ``` -------------------------------- ### GitLab Branch Protection CE Example Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/resources/branch_protection.md This example shows how to configure basic branch protection for a GitLab project using Community Edition features. It sets push and merge access levels to 'developer' and allows force pushes. ```terraform resource "gitlab_branch_protection" "ce_branch" { project = "12345" branch = "BranchProtected" push_access_level = "developer" merge_access_level = "developer" allow_force_push = true } ``` -------------------------------- ### Create a service account and a personal access token Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/resources/instance_service_account.md This example demonstrates how to create a service account and then generate a personal access token for it. Note that the service account requires admin privileges and is not available on gitlab.com. The token is scoped to 'api' and expires on January 1, 2026. ```terraform resource "gitlab_instance_service_account" "example_sa" { name = "example-name" username = "example-username" email = "custom_email@gitlab.example.com" timeouts = { # service accounts do not delete instantly, but you can set up a timeout on deletion delete = "3m" } } resource "gitlab_personal_access_token" "example_token" { user_id = gitlab_instance_service_account.example_sa.service_account_id name = "Example personal access token for a service account" expires_at = "2026-01-01" scopes = ["api"] } ``` -------------------------------- ### Create a Project Wiki Page Source: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/blob/main/docs/resources/project_wiki_page.md Use this resource to create a new wiki page for a GitLab project. Ensure the project ID and a unique slug are provided. ```terraform resource "gitlab_project_wiki_page" "example" { project = "12345" slug = "test-wiki-page" # Unique slug for the wiki page title = "Test Wiki Page" content = <