Data Sources
Look up existing DevZero resources by name without managing them with Pulumi.
Data Sources
Data sources let you look up existing DevZero resources that were not created by Pulumi — 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.
getClusterIdByName
Looks up an existing cluster by name and returns its ID. This is useful when a cluster was registered outside of Pulumi and you need its ID to attach a WorkloadPolicyTarget or inject it into a Kubernetes secret / values.yaml.
Example
import * as pulumi from "@pulumi/pulumi";
import { resources } from "@devzero/pulumi-devzero";
// Look up a manually registered cluster by name
const existing = await resources.getClusterIdByName({
name: "my-existing-cluster",
// teamId is optional — defaults to devzero:teamId from provider config
// region: "us-east-1", // optional: filter by region
// cloudProvider: "AWS", // optional: AWS | GCP | AKS | OCI
// liveness: "PREFER_LIVE", // optional: IGNORE | PREFER_LIVE | REQUIRE_LIVE
});
// Attach a workload policy to the existing cluster
const target = new resources.WorkloadPolicyTarget("my-target", {
name: "my-target",
policyId: policy.id,
clusterIds: [existing.clusterId],
kindFilter: ["Deployment"],
enabled: true,
});
export const existingClusterId = existing.clusterId;import pulumi
from pulumi_devzero import resources
# Look up a manually registered cluster by name
existing = resources.get_cluster_id_by_name(
name="my-existing-cluster",
# team_id is optional — defaults to devzero:teamId from provider config
# region="us-east-1", # optional: filter by region
# cloud_provider="AWS", # optional: AWS | GCP | AKS | OCI
# liveness="PREFER_LIVE", # optional: IGNORE | PREFER_LIVE | REQUIRE_LIVE
)
# Attach a workload policy to the existing cluster
target = resources.WorkloadPolicyTarget("my-target",
args=resources.WorkloadPolicyTargetArgs(
name="my-target",
policy_id=policy.id,
cluster_ids=[existing.cluster_id],
kind_filter=["Deployment"],
enabled=True,
)
)
pulumi.export("existing_cluster_id", existing.cluster_id)package main
import (
"github.com/devzero-inc/pulumi-provider-devzero/sdk/go/devzero/resources"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
// Look up a manually registered cluster by name
existing, err := resources.GetClusterIdByName(ctx, &resources.GetClusterIdByNameArgs{
Name: "my-existing-cluster",
// TeamId is optional — defaults to devzero:teamId from provider config
// Region: pulumi.StringRef("us-east-1"), // optional: filter by region
// CloudProvider: pulumi.StringRef("AWS"), // optional: AWS | GCP | AKS | OCI
// Liveness: pulumi.StringRef("PREFER_LIVE"), // optional: IGNORE | PREFER_LIVE | REQUIRE_LIVE
})
if err != nil {
return err
}
// Attach a workload policy to the existing cluster
_, err = resources.NewWorkloadPolicyTarget(ctx, "my-target", &resources.WorkloadPolicyTargetArgs{
Name: pulumi.String("my-target"),
PolicyId: policy.ID(),
ClusterIds: pulumi.StringArray{pulumi.String(existing.ClusterId)},
KindFilter: pulumi.StringArray{pulumi.String("Deployment")},
Enabled: pulumi.BoolPtr(true),
})
if err != nil {
return err
}
ctx.Export("existingClusterId", pulumi.String(existing.ClusterId))
return nil
})
}Inputs
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Name of the cluster to look up |
teamId | string | No | Team to search within. Defaults to devzero:teamId from provider config |
region | string | No | Filter by region name (e.g. us-east-1) |
cloudProvider | 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) |
Python uses snake_case: team_id, cloud_provider. Go uses PascalCase: TeamId, CloudProvider.
Outputs
| Field | Type | Description |
|---|---|---|
clusterId | string | UUID of the matching cluster |
Python: cluster_id. Go: ClusterId.
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.