Skip to content

Support looking up rhcs_cluster_rosa_hcp data source by cluster name (not just id) #1254

Description

@lindleywhite

Problem

The rhcs_cluster_rosa_hcp data source only accepts id (a Required string) as its lookup key:

data "rhcs_cluster_rosa_hcp" "cluster" {
  id = "cluster-id-123"
}

There is no way to look up a cluster by name. This is a real gap versus the underlying OCM API, which already supports name-based search — rosa describe cluster -c <name> and the raw clusters_mgmt REST API (GET /api/clusters_mgmt/v1/clusters?search=name+is+'<name>') both resolve a cluster by name today. I verified this directly:

curl -s -H "Authorization: Bearer $TOKEN" \
  "https://api.openshift.com/api/clusters_mgmt/v1/clusters?search=name%20is%20'imp-int-use2'"

returns the full cluster object (including id, aws.sts.oidc_endpoint_url, etc.) keyed only by name.

The underlying ocm-sdk-go client used by the provider also already exposes this capability:

clusterCollection.List().Search("name is '<name>'").SendContext(ctx)

(clusters_client.goClustersListRequest.Search(value string)).

Why this matters

In multi-workspace Terraform setups, a common pattern is:

  1. Workspace A creates the ROSA HCP cluster (rhcs_cluster_rosa_hcp resource) and knows the cluster name at plan time (it's a variable), but the id only exists after creation.
  2. Workspace B needs to configure the cluster after the fact (identity providers, group membership, etc.) and needs the id / sts.oidc_endpoint_url to reference it.

Today, the only ways to bridge this gap are:

  • A terraform_remote_state cross-workspace lookup (many organizations intentionally avoid this pattern for state-isolation/security reasons), or
  • Manually running rosa describe cluster -c <name> -o json | jq -r .id and hand-copying the id into workspace B's tfvars after every cluster (re)creation.

Since the cluster name is already known statically (it's a required input to the rhcs_cluster_rosa_hcp resource), letting the data source accept name as an alternate lookup key would let downstream workspaces resolve id (and other computed attributes like sts.oidc_endpoint_url) without remote state or manual copy/paste — using only a name-keyed data source, consistent with how the OCM API itself already works.

Proposed change

  • Make id Optional + Computed instead of Required.
  • Add name as Optional + Computed.
  • Add a schema-level validator requiring exactly one of id / name to be set.
  • In the data source's Read():
    • If id is set, keep the existing direct clusterCollection.Cluster(id).Get() path.
    • If only name is set, call clusterCollection.List().Search("name is '<name>'").SendContext(ctx), error if Total() != 1 (not found / ambiguous), and use the resulting cluster's id to populate the rest of the state (same as today).

Happy to submit a PR implementing this if the change is welcome — wanted to open the issue first per the contributing guide before submitting one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions