# Terraform-Provider-Gitlabci: Register GitLab CI Runners


I'm a huge fan of terraform, so when I needed to build out cloud
infrastructure for GitLab CI/CD it was the first thing I reached for.  The
native `terraform-provider-gitlab` was very useful, but left out one critical
detail: it was not possible to [register a runner](https://docs.gitlab.com/runner/register/).

Ouch. :anger:

<!--more-->

This left a rather annoyingly awkward gap in my terraform configurations, as
I'd need to provision a runner token _outside_ of terraform.  I messed around
with this, coming up with a couple... interesting approaches, but ultimately I
realized that the only proper solution to this (read: that wasn't just a giant
hack) would require writing a provider.

## `terraform-provider-gitlabci`

Recently I've had some free time, so I cleaned it up a bit and published it.

* [terraform registry (docs, etc)](https://registry.terraform.io/providers/rsrchboy/gitlabci/latest/docs)
* [:(fab fa-gitlab): source hosted at GitLab](https://gitlab.com/rsrchboy/terraform-provider-gitlabci)

## A quick example

Documentation and the like can be found over at the [terraform registry](https://registry.terraform.io/providers/rsrchboy/gitlabci/latest/docs),
but here's a quick example with only a minimum of hand-wavey:

```terraform
terraform {
  required_providers {
    gitlabci = {
      source = "registry.terraform.io/rsrchboy/gitlabci"
    }
    gitlab = {
      source = "registry.terraform.io/gitlabhq/gitlab"
    }
  }
}

provider "gitlabci" { }
provider "gitlab"   { }

data "gitlab_project" "this" {
  id = "rsrchboy/terraform-provider-gitlabci"
}

resource "gitlabci_runner_token" "this" {
  registration_token = data.gitlab_project.this.runners_token
  locked             = true
  tags = [
    "jinx",
    "powder",
    "cupcake",
  ]
}

output "token" {
  sensitive = true
  value     = gitlabci_runner_token.this.token
}
```

Note how, using both the `gitlab` and `gitlabci` providers we can now register
GitLab runners.  The example shows us using a registration token obtained from
a project data source, but `terraform-provider-gitlabci` doesn't care if it's
a project, group, or even instance registration token.  Additionally, while
the `gitlab` provider does require API access, the `gitlabci` provider only
requires a valid registration token.

Enjoy! :(fas fa-grin):


---

> Author: Chris Weyl  
> URL: https://weyl.io/2022/01/terraform-provider-gitlabci/  

