gitlab_cluster_agent_token (Resource)

The gitlab_cluster_agent_token resource allows to manage the lifecycle of a token for a GitLab Agent for Kubernetes.

Upstream API: GitLab REST API docs

Example Usage

// Create token for an agent
resource "gitlab_cluster_agent_token" "example" {
  project     = "12345"
  agent_id    = 42
  name        = "some-token"
  description = "some token"
}

// The following example creates a GitLab Agent for Kubernetes in a given project,
// creates a token and install the `gitlab-agent` Helm Chart.
// (see https://gitlab.com/gitlab-org/charts/gitlab-agent)
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
  }
}

Schema

Required

Optional

Read-Only

Import

Import is supported using the following syntax:

# A token for a GitLab Agent for Kubernetes can be imported with the following command and the id pattern `<project>:<agent-id>:<token-id>`:
terraform import gitlab_cluster_agent_token.example '12345:42:1'

# ATTENTION: the `token` resource attribute is not available for imported resources as this information cannot be read from the GitLab API.