gitlab_cluster_agent (Resource)

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

Upstream API: GitLab REST API docs

Example Usage

resource "gitlab_cluster_agent" "example" {
  project = "12345"
  name    = "agent-1"
}

// Optionally, configure the agent as described in
// https://docs.gitlab.com/ee/user/clusters/agent/install/index.html#create-an-agent-configuration-file
resource "gitlab_repository_file" "example_agent_config" {
  project   = gitlab_cluster_agent.example.project
  branch    = "main" // or use the `default_branch` attribute from a project data source / resource
  file_path = ".gitlab/agents/${gitlab_cluster_agent.example.name}/config.yaml"
  content = base64encode(<<CONTENT
# the GitLab Agent for Kubernetes configuration goes here ...
  CONTENT
  )
  author_email   = "terraform@example.com"
  author_name    = "Terraform"
  commit_message = "feature: add agent config for ${gitlab_cluster_agent.example.name} [skip ci]"
}
# the GitLab Agent for Kubernetes configuration goes here ...
  CONTENT
  )
  author_email   = "terraform@example.com"
  author_name    = "Terraform"
  commit_message = "feature: add agent config for ${gitlab_cluster_agent.example.name} [skip ci]"
}

Schema

Required

Read-Only

Import

Import is supported using the following syntax:

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