cockroachdb / terraform-provider-cockroach

Terraform provider for CockroachDB Cloud
Apache License 2.0
56 stars 10 forks source link

Unable to retrieve connection URL for Serverless clusters #71

Closed 1lann closed 1 year ago

1lann commented 1 year ago

I can't seem to figure out a way to construct the connection URL for a serverless cluster from a cockroach_cluster resource. There's the sql_dns field of a region, but that only provides an endpoint like free-tier.gcp-us-central1.cockroachlabs.cloud, which lacks the tenant routing ID, and is not usable to determine the proxy endpoint which looks like tenant-name-1234.5xj.cockroachlabs.cloud.

Although I could technically use the options DSN parameter and pass the routing ID via the cluster option, this is inconvenient as it's not supported by configuration in some applications.

This might be a shortcoming of the Cockroach Cloud API as well as I don't see it exposed there either.

It would be nice if this could be added to the provider, and for the data source as well.

jonohill commented 1 year ago

I've encountered this today too, thanks for the options parameter hint. I agree the proxy endpoint should be added to the API/provider.

The options parameter seems to be supported in my case, so crafting the url is something like postgresql://${cockroach_sql_user.db.name}:${cockroach_sql_user.db.password}@${cockroach_cluster.db.regions[0].sql_dns}:26257/defaultdb?sslmode=verify-full&options=${urlencode("--cluster=${cockroach_cluster.db.serverless.routing_id}")}

erademacher commented 1 year ago

Hey, thanks for bringing this up. I'm pleased to announce the addition of a cockroach_connection_string datasource in 0.4.1! You should see the tenant ID correctly included in the server URL.

There's also a cockroach_cluster_cert data source, but that's more relevant for dedicated clusters.