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.go — ClustersListRequest.Search(value string)).
Why this matters
In multi-workspace Terraform setups, a common pattern is:
- 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.
- 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.
Problem
The
rhcs_cluster_rosa_hcpdata source only acceptsid(aRequiredstring) as its lookup key: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 rawclusters_mgmtREST API (GET /api/clusters_mgmt/v1/clusters?search=name+is+'<name>') both resolve a cluster by name today. I verified this directly:returns the full cluster object (including
id,aws.sts.oidc_endpoint_url, etc.) keyed only by name.The underlying
ocm-sdk-goclient used by the provider also already exposes this capability:(
clusters_client.go—ClustersListRequest.Search(value string)).Why this matters
In multi-workspace Terraform setups, a common pattern is:
rhcs_cluster_rosa_hcpresource) and knows the cluster name at plan time (it's a variable), but theidonly exists after creation.id/sts.oidc_endpoint_urlto reference it.Today, the only ways to bridge this gap are:
terraform_remote_statecross-workspace lookup (many organizations intentionally avoid this pattern for state-isolation/security reasons), orrosa describe cluster -c <name> -o json | jq -r .idand hand-copying theidinto workspace B'stfvarsafter every cluster (re)creation.Since the cluster
nameis already known statically (it's a required input to therhcs_cluster_rosa_hcpresource), letting the data source acceptnameas an alternate lookup key would let downstream workspaces resolveid(and other computed attributes likests.oidc_endpoint_url) without remote state or manual copy/paste — using only aname-keyed data source, consistent with how the OCM API itself already works.Proposed change
idOptional + Computedinstead ofRequired.nameasOptional + Computed.id/nameto be set.Read():idis set, keep the existing directclusterCollection.Cluster(id).Get()path.nameis set, callclusterCollection.List().Search("name is '<name>'").SendContext(ctx), error ifTotal() != 1(not found / ambiguous), and use the resulting cluster'sidto 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.