Skip to main content

cloider_cluster data source (Terraform)

The cloider_cluster data source reads an existing Cloider Kubernetes cluster, found by id or by name, without managing it. Use it when one configuration owns the cluster (or it was created in the dashboard) and another configuration deploys into it: the data source gives the second configuration the cluster's kube_config for the kubernetes and helm providers, and its id for database trusted sources and targets.

At a glance​

ArgumentsExactly one of id or name
Returnsid, name, version, label, status, created_at, kube_config (sensitive)
Changes anything?No, it only reads
Resource versioncloider_cluster resource

Example usage​

Look up a cluster by name​

main.tf
data "cloider_cluster" "production" {
name = "production"
}

output "production_cluster_id" {
value = data.cloider_cluster.production.id
}

Configure the kubernetes and helm providers​

providers.tf
data "cloider_cluster" "production" {
name = "production"
}

provider "kubernetes" {
host = data.cloider_cluster.production.kube_config.host
cluster_ca_certificate = data.cloider_cluster.production.kube_config.cluster_ca_certificate
client_certificate = data.cloider_cluster.production.kube_config.client_certificate
client_key = data.cloider_cluster.production.kube_config.client_key
}

provider "helm" {
kubernetes = {
host = data.cloider_cluster.production.kube_config.host
cluster_ca_certificate = data.cloider_cluster.production.kube_config.cluster_ca_certificate
client_certificate = data.cloider_cluster.production.kube_config.client_certificate
client_key = data.cloider_cluster.production.kube_config.client_key
}
}

Because a data source is read before the plan, the providers are configured with real values from the start. This is the most reliable way to deploy into a cluster, see Kubernetes and Helm.

Look up a cluster by id​

When several clusters share a name, use the id:

main.tf
data "cloider_cluster" "staging" {
id = "x8f2kq"
}

Trust an existing cluster in a new database​

main.tf
data "cloider_cluster" "production" {
name = "production"
}

resource "cloider_database" "orders" {
name = "orders-db"
engine = "postgresql"
trusted_sources = ["cluster:${data.cloider_cluster.production.id}"]
}

Argument reference​

ArgumentTypeRequiredDescription
idStringOne of id or nameThe cluster's id, such as x8f2kq
nameStringOne of id or nameThe cluster's name. Names don't have to be unique, so a name that several clusters have is refused: use the id then

Setting both, or neither, fails at plan time.

Attribute reference​

AttributeTypeSensitiveDescription
idStringNoThe cluster's id
nameStringNoThe cluster's name
versionStringNoThe Kubernetes version
labelStringNoThe name the dashboard shows
statusStringNoCreating, Starting, Ready, Pausing, Paused or Terminating
created_atStringNoWhen the cluster was created, in RFC 3339
kube_configObjectYesraw, host, cluster_ca_certificate, client_certificate, client_key and token, the same as on the resource. Null until the cluster is ready

Deleted clusters are never found.

Errors​

ErrorCause
No such cluster: There is no cluster named "production", see 'cloider cluster list'.No cluster in the account has that name
No such cluster: There is no cluster "x8f2kq", see 'cloider cluster list -o wide'.No cluster in the account has that id
Several clusters have this name: Clusters x8f2kq (staging), h3j8pw (staging-1) are all named "staging", give the id of the one to use.The name is shared, use id

Frequently asked questions

How do I use an existing Cloider cluster in Terraform without managing it?

Use the cloider_cluster data source with name or id. It returns the cluster's id and kube_config without creating, changing or deleting anything.

Why does the cloider_cluster data source say several clusters have this name?

Cluster names don't have to be unique. When two clusters share the name, look the cluster up by id instead. The error lists the ids and labels of the matching clusters.

Why is kube_config null?

The cluster has no kubeconfig until it is ready. Check the status attribute, wait until the cluster is Ready, and run terraform plan again.