Data Sources
Look up existing DevZero resources by name without managing them with Terraform.
Data Sources
Data sources let you look up existing DevZero resources that were not created by Terraform — for example, clusters registered manually via the DevZero dashboard or CLI. Use them to retrieve IDs you need to attach policies or pass into other resources.
devzero_get_cluster_id_by_name
Looks up an existing cluster by name and returns its ID. This is useful when a cluster was registered outside of Terraform and you need its ID to attach a devzero_workload_policy_target or reference it in another resource.
Example
# Look up a cluster ID by name using the provider's default team ID
data "devzero_get_cluster_id_by_name" "example" {
name = "my-cluster"
}
output "cluster_id" {
value = data.devzero_get_cluster_id_by_name.example.cluster_id
}# Look up a cluster ID with optional filters
data "devzero_get_cluster_id_by_name" "filtered" {
name = "my-cluster"
region = "us-east-1" # optional: filter by region
cloud_provider = "AWS" # optional: filter by cloud provider (AWS | GCP | AKS | OCI)
liveness = "PREFER_LIVE" # optional: IGNORE | PREFER_LIVE | REQUIRE_LIVE
}
# Attach a workload policy to the existing cluster
resource "devzero_workload_policy_target" "my_target" {
name = "my-target"
policy_id = devzero_workload_policy.example.id
cluster_ids = [data.devzero_get_cluster_id_by_name.filtered.cluster_id]
kind_filter = ["Deployment"]
enabled = true
}
output "filtered_cluster_id" {
value = data.devzero_get_cluster_id_by_name.filtered.cluster_id
}Inputs
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Name of the cluster to look up |
team_id | string | No | Team to search within. Defaults to team_id from provider config |
region | string | No | Filter by region name (e.g. us-east-1) |
cloud_provider | string | No | Filter by cloud provider: AWS, GCP, AKS, OCI |
liveness | string | No | Heartbeat filter: IGNORE (default — newest by created_at), PREFER_LIVE (live first, fallback to newest), REQUIRE_LIVE (404 if no heartbeat within 60 min) |
Outputs
| Field | Type | Description |
|---|---|---|
cluster_id | string | UUID of the matching cluster |
Note: If multiple clusters share the same name, the newest one (by
created_at) is returned by default. Use thelivenessfield to prefer or require a cluster whose zxporter agent has reported a heartbeat within the last 60 minutes. Ensure cluster names are unique within your team to avoid unexpected results.