|
3 | 3 | page_title: "gitlab_runner Resource - terraform-provider-gitlab"
|
4 | 4 | subcategory: ""
|
5 | 5 | description: |-
|
6 |
| - The gitlab_runner resource allows registering a runner, either at an instance level |
7 |
| - or at a group level. The runner will be registered at a group level if the token used is from a group, or at an |
8 |
| - instance level if the token used is for the instance. |
| 6 | + The gitlab_runner resource allows to manage the lifecycle of a runner. |
| 7 | + A runner can either be registered at an instance level or group level. |
| 8 | + 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. |
9 | 9 | Upstream API: GitLab REST API docs https://docs.gitlab.com/ee/api/runners.html#register-a-new-runner
|
10 | 10 | ---
|
11 | 11 |
|
12 | 12 | # gitlab_runner (Resource)
|
13 | 13 |
|
14 |
| -The `gitlab_runner` resource allows registering a runner, either at an instance level |
15 |
| -or at a group level. The runner will be registered at a group level if the token used is from a group, or at an |
16 |
| -instance level if the token used is for the instance. |
| 14 | +The `gitlab_runner` resource allows to manage the lifecycle of a runner. |
| 15 | + |
| 16 | +A runner can either be registered at an instance level or group level. |
| 17 | +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. |
17 | 18 |
|
18 | 19 | **Upstream API**: [GitLab REST API docs](https://docs.gitlab.com/ee/api/runners.html#register-a-new-runner)
|
19 | 20 |
|
20 | 21 | ## Example Usage
|
21 | 22 |
|
22 | 23 | ```terraform
|
23 |
| -# Basic GitLab Runner |
24 |
| -resource "gitlab_runner" "this" { |
25 |
| - token = "12345" |
| 24 | +# Basic GitLab Group Runner |
| 25 | +resource "gitlab_group" "my_group" { |
| 26 | + name = "my runner" |
| 27 | + description = "group that holds the runners" |
| 28 | +} |
| 29 | +resource "gitlab_runner" "basic_runner" { |
| 30 | + registration_token = gitlab_group.my_group.runners_token |
26 | 31 | }
|
27 | 32 |
|
28 | 33 | # GitLab Runner that runs only tagged jobs
|
29 | 34 | resource "gitlab_runner" "tagged_only" {
|
30 |
| - token = "12345" |
31 |
| - description = "I only run tagged jobs" |
| 35 | + registration_token = gitlab_group.my_group.runners_token |
| 36 | + description = "I only run tagged jobs" |
32 | 37 |
|
33 | 38 | run_untagged = "false"
|
34 | 39 | tag_list = ["tag_one", "tag_two"]
|
35 | 40 | }
|
36 | 41 |
|
37 | 42 | # GitLab Runner that only runs on protected branches
|
38 | 43 | resource "gitlab_runner" "protected" {
|
39 |
| - token = "12345" |
40 |
| - description = "I only run protected jobs" |
| 44 | + registration_token = gitlab_group.my_group.runners_token |
| 45 | + description = "I only run protected jobs" |
41 | 46 |
|
42 | 47 | access_level = "ref_protected"
|
43 | 48 | }
|
| 49 | +
|
| 50 | +# Generate a `config.toml` file that you can use to create a runner |
| 51 | +# This is the typical workflow for this resource, using it to create an authentication_token which can then be used |
| 52 | +# to generate the `config.toml` file to prevent re-registering the runner every time new hardware is created. |
| 53 | +
|
| 54 | +resource "gitlab_group" "my_custom_group" { |
| 55 | + name = "my custom runner" |
| 56 | + description = "group that holds the custom runners" |
| 57 | +} |
| 58 | +
|
| 59 | +resource "gitlab_runner" "my_runner" { |
| 60 | + registration_token = gitlab_group.my_custom_group.runners_token |
| 61 | +} |
| 62 | +
|
| 63 | +# This creates a configuration for a local "shell" runner, but can be changed to generate whatever is needed. |
| 64 | +# Place this configuration file on a server at `/etc/gitlab-runner/config.toml`, then run `gitlab-runner start`. |
| 65 | +# See https://docs.gitlab.com/runner/configuration/advanced-configuration.html for more information. |
| 66 | +resource "local_file" "config" { |
| 67 | + filename = "${path.module}/config.toml" |
| 68 | + content = <<CONTENT |
| 69 | + concurrent = 1 |
| 70 | +
|
| 71 | + [[runners]] |
| 72 | + name = "Hello Terraform" |
| 73 | + url = "https://example.gitlab.com/" |
| 74 | + token = "${gitlab_runner.my_runner.authentication_token}" |
| 75 | + executor = "shell" |
| 76 | + |
| 77 | + CONTENT |
| 78 | +} |
44 | 79 | ```
|
45 | 80 |
|
46 | 81 | <!-- schema generated by tfplugindocs -->
|
47 | 82 | ## Schema
|
48 | 83 |
|
49 | 84 | ### Required
|
50 | 85 |
|
51 |
| -- `token` (String, Sensitive) The registration token used to register the runner |
| 86 | +- `registration_token` (String, Sensitive) The registration token used to register the runner. |
52 | 87 |
|
53 | 88 | ### Optional
|
54 | 89 |
|
55 |
| -- `access_level` (String) The access_level of the runner. Valid values are: `not_protected`, `ref_protected` |
56 |
| -- `description` (String) The runner's description' |
| 90 | +- `access_level` (String) The access_level of the runner. Valid values are: `not_protected`, `ref_protected`. |
| 91 | +- `description` (String) The runner's description. |
57 | 92 | - `id` (String) The ID of this resource.
|
58 |
| -- `locked` (Boolean) Whether the runner should be locked for current project |
59 |
| -- `maximum_timeout` (Number) Maximum timeout set when this runner handles the job |
60 |
| -- `paused` (Boolean) Whether the runner should ignore new jobs |
61 |
| -- `run_untagged` (Boolean) Whether the runner should handle untagged jobs |
62 |
| -- `tag_list` (List of String) List of runner’s tags |
| 93 | +- `locked` (Boolean) Whether the runner should be locked for current project. |
| 94 | +- `maximum_timeout` (Number) Maximum timeout set when this runner handles the job. |
| 95 | +- `paused` (Boolean) Whether the runner should ignore new jobs. |
| 96 | +- `run_untagged` (Boolean) Whether the runner should handle untagged jobs. |
| 97 | +- `tag_list` (List of String) List of runner’s tags. |
63 | 98 |
|
64 | 99 | ### Read-Only
|
65 | 100 |
|
66 | 101 | - `authentication_token` (String, Sensitive) The authentication token used for building a config.toml file. This value is not present when imported.
|
67 | 102 | - `status` (String) The status of runners to show, one of: online and offline. active and paused are also possible values
|
68 |
| - which were deprecated in GitLab 14.8 and will be removed in GitLab 16.0 |
| 103 | + which were deprecated in GitLab 14.8 and will be removed in GitLab 16.0. |
69 | 104 |
|
70 | 105 | ## Import
|
71 | 106 |
|
|
0 commit comments