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
// 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
}
}
agent_id
(Number) The ID of the agent.name
(String) The Name of the agent.project
(String) ID or full path of the project maintained by the authenticated user.description
(String) The Description for the agent.created_at
(String) The ISO8601 datetime when the agent was created.created_by_user_id
(Number) The ID of the user who created the agent.id
(String) The ID of this resource.last_used_at
(String) The ISO8601 datetime when the token was last used.status
(String) The status of the token. Valid values are active
, revoked
.token
(String) The secret token for the agent. The token
is not available in imported resources.token_id
(Number) The ID of the token.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.