Skip to content

Commit 8a3edf8

Browse files
committed
Initial push of runner resource
1 parent cd05af8 commit 8a3edf8

File tree

4 files changed

+231
-129
lines changed

4 files changed

+231
-129
lines changed

docs/resources/runner.md

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,69 +3,104 @@
33
page_title: "gitlab_runner Resource - terraform-provider-gitlab"
44
subcategory: ""
55
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.
99
Upstream API: GitLab REST API docs https://docs.gitlab.com/ee/api/runners.html#register-a-new-runner
1010
---
1111

1212
# gitlab_runner (Resource)
1313

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.
1718

1819
**Upstream API**: [GitLab REST API docs](https://docs.gitlab.com/ee/api/runners.html#register-a-new-runner)
1920

2021
## Example Usage
2122

2223
```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
2631
}
2732
2833
# GitLab Runner that runs only tagged jobs
2934
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"
3237
3338
run_untagged = "false"
3439
tag_list = ["tag_one", "tag_two"]
3540
}
3641
3742
# GitLab Runner that only runs on protected branches
3843
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"
4146
4247
access_level = "ref_protected"
4348
}
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+
}
4479
```
4580

4681
<!-- schema generated by tfplugindocs -->
4782
## Schema
4883

4984
### Required
5085

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.
5287

5388
### Optional
5489

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.
5792
- `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.
6398

6499
### Read-Only
65100

66101
- `authentication_token` (String, Sensitive) The authentication token used for building a config.toml file. This value is not present when imported.
67102
- `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.
69104

70105
## Import
71106

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,56 @@
1-
# Basic GitLab Runner
2-
resource "gitlab_runner" "this" {
3-
token = "12345"
1+
# Basic GitLab Group Runner
2+
resource "gitlab_group" "my_group" {
3+
name = "my runner"
4+
description = "group that holds the runners"
5+
}
6+
resource "gitlab_runner" "basic_runner" {
7+
registration_token = gitlab_group.my_group.runners_token
48
}
59

610
# GitLab Runner that runs only tagged jobs
711
resource "gitlab_runner" "tagged_only" {
8-
token = "12345"
9-
description = "I only run tagged jobs"
12+
registration_token = gitlab_group.my_group.runners_token
13+
description = "I only run tagged jobs"
1014

1115
run_untagged = "false"
1216
tag_list = ["tag_one", "tag_two"]
1317
}
1418

1519
# GitLab Runner that only runs on protected branches
1620
resource "gitlab_runner" "protected" {
17-
token = "12345"
18-
description = "I only run protected jobs"
21+
registration_token = gitlab_group.my_group.runners_token
22+
description = "I only run protected jobs"
1923

2024
access_level = "ref_protected"
21-
}
25+
}
26+
27+
# Generate a `config.toml` file that you can use to create a runner
28+
# This is the typical workflow for this resource, using it to create an authentication_token which can then be used
29+
# to generate the `config.toml` file to prevent re-registering the runner every time new hardware is created.
30+
31+
resource "gitlab_group" "my_custom_group" {
32+
name = "my custom runner"
33+
description = "group that holds the custom runners"
34+
}
35+
36+
resource "gitlab_runner" "my_runner" {
37+
registration_token = gitlab_group.my_custom_group.runners_token
38+
}
39+
40+
# This creates a configuration for a local "shell" runner, but can be changed to generate whatever is needed.
41+
# Place this configuration file on a server at `/etc/gitlab-runner/config.toml`, then run `gitlab-runner start`.
42+
# See https://docs.gitlab.com/runner/configuration/advanced-configuration.html for more information.
43+
resource "local_file" "config" {
44+
filename = "${path.module}/config.toml"
45+
content = <<CONTENT
46+
concurrent = 1
47+
48+
[[runners]]
49+
name = "Hello Terraform"
50+
url = "https://example.gitlab.com/"
51+
token = "${gitlab_runner.my_runner.authentication_token}"
52+
executor = "shell"
53+
54+
CONTENT
55+
}
56+

0 commit comments

Comments
 (0)