The gitlab_runner
resource allows to manage the lifecycle of a runner.
A runner can either be registered at an instance level or group level. The runner will be registered at a group level if the token used is from a group, or at an instance level if the token used is for the instance.
~ > Using this resource will register a runner using the deprecated registration_token
flow. To use the new authentication_token
flow instead,
use the gitlab_user_runner
resource!
Upstream API: GitLab REST API docs
# Basic GitLab Group Runner
resource "gitlab_group" "my_group" {
name = "my runner"
description = "group that holds the runners"
}
resource "gitlab_runner" "basic_runner" {
registration_token = gitlab_group.my_group.runners_token
}
# GitLab Runner that runs only tagged jobs
resource "gitlab_runner" "tagged_only" {
registration_token = gitlab_group.my_group.runners_token
description = "I only run tagged jobs"
run_untagged = "false"
tag_list = ["tag_one", "tag_two"]
}
# GitLab Runner that only runs on protected branches
resource "gitlab_runner" "protected" {
registration_token = gitlab_group.my_group.runners_token
description = "I only run protected jobs"
access_level = "ref_protected"
}
# Generate a `config.toml` file that you can use to create a runner
# This is the typical workflow for this resource, using it to create an authentication_token which can then be used
# to generate the `config.toml` file to prevent re-registering the runner every time new hardware is created.
resource "gitlab_group" "my_custom_group" {
name = "my custom runner"
description = "group that holds the custom runners"
}
resource "gitlab_runner" "my_runner" {
registration_token = gitlab_group.my_custom_group.runners_token
}
# This creates a configuration for a local "shell" runner, but can be changed to generate whatever is needed.
# Place this configuration file on a server at `/etc/gitlab-runner/config.toml`, then run `gitlab-runner start`.
# See https://docs.gitlab.com/runner/configuration/advanced-configuration.html for more information.
resource "local_file" "config" {
filename = "${path.module}/config.toml"
content = <<CONTENT
concurrent = 1
[[runners]]
name = "Hello Terraform"
url = "https://example.gitlab.com/"
token = "${gitlab_runner.my_runner.authentication_token}"
executor = "shell"
CONTENT
}
concurrent = 1
[[runners]]
name = "Hello Terraform"
url = "https://example.gitlab.com/"
token = "${gitlab_runner.my_runner.authentication_token}"
executor = "shell"
CONTENT
}
registration_token
(String, Sensitive) The registration token used to register the runner.access_level
(String) The access_level of the runner. Valid values are: not_protected
, ref_protected
.description
(String) The runner's description.locked
(Boolean) Whether the runner should be locked for current project.maximum_timeout
(Number) Maximum timeout set when this runner handles the job.paused
(Boolean) Whether the runner should ignore new jobs.run_untagged
(Boolean) Whether the runner should handle untagged jobs.tag_list
(Set of String) List of runner’s tags.authentication_token
(String, Sensitive) The authentication token used for building a config.toml file. This value is not present when imported.id
(String) The ID of this resource.status
(String) The status of runners to show, one of: online and offline. active and paused are also possible values
which were deprecated in GitLab 14.8 and will be removed in GitLab 16.0.Import is supported using the following syntax:
# A GitLab Runner can be imported using the runner's ID, eg
terraform import gitlab_runner.this 1