Clusters
Register and manage DevZero clusters with Terraform.
Clusters
The devzero_cluster resource registers a Kubernetes cluster with DevZero. Once created, it outputs a cluster id and a token that operators use to connect to the DevZero platform.
For a higher-level approach that also handles operator installation, see the devzero-inc/cluster/devzero module described in the overview.
Example
resource "devzero_cluster" "production" {
name = "production-cluster"
}
output "cluster_id" {
value = devzero_cluster.production.id
}
output "cluster_token" {
value = devzero_cluster.production.token
sensitive = true
}Arguments
| Parameter | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Unique name for the cluster |
team_id | string | No | ID of the team the cluster is registered in, such as a devzero_team's id. Defaults to the provider's team_id. Needs provider 0.3.0 or later. |
Registering in Another Team
Set team_id to register the cluster in a team other than the provider's, such as a customer's team started with devzero_team, or a customer's existing team your service account was given access to (see Partner Teams):
resource "devzero_cluster" "acme_prod" {
name = "acme-prod"
team_id = devzero_team.acme.id
}team_id is fixed once the cluster is registered. On an existing cluster, a plan that changes team_id, or leaves it unknown until apply, is refused: set it back, or remove team_id to keep the cluster's team. Terraform never moves a cluster to another team. To have a cluster in another team, add a new devzero_cluster there.
A cluster registered with a provider release before 0.3.0 is in the provider's team and stays there.
Attributes
| Attribute | Type | Description |
|---|---|---|
id | string | The cluster ID assigned by DevZero |
token | string (sensitive) | Authentication token used by operators to connect to the cluster |
The token is sensitive -- always mark outputs that reference it with sensitive = true.
Import
You can import an existing cluster into Terraform state:
# A cluster of the provider's team
terraform import devzero_cluster.production <cluster_id>
# A cluster of another team, such as one a devzero_team started
terraform import devzero_cluster.production <team_id>/<cluster_id>The first apply after an import issues a new cluster token. The cluster's agents stop reporting until they run with the new token.
For the config-driven import block workflow (recommended -- lets you verify a clean import with terraform plan before applying), see Importing Resources.
Module Alternative
Instead of managing the devzero_cluster resource directly, you can use the devzero-inc/cluster/devzero module which registers the cluster and installs operators in a single step:
module "devzero_cluster" {
source = "devzero-inc/cluster/devzero"
version = "~> 0.2"
cluster_name = "my-cluster"
team_id = devzero_team.acme.id
}Module 0.2.0 takes the same team_id and passes it to its devzero_cluster. Left out, the cluster registers in the provider's team. Once the cluster is registered, a change to team_id is refused at plan, so the module never moves or re-creates a cluster. Module 0.2.0 needs provider 0.3.0 or later. Its outputs are cluster_id and cluster_token (sensitive).