Closed jlforester closed 4 years ago
@jlforester Thank you for the report. The returned private link connection string was not yet available for this version, 0.4.0. We'll ensure we add in support as soon as we can get it on the schedule.
@jlforester our documentation is now updated with how to get the correct connection strings: https://docs.atlas.mongodb.com/reference/api/clusters-get-all/ and https://docs.atlas.mongodb.com/reference/api/clusters-get-one/ This means we can now update the provider to support this. We have this on our plan and we'll update when completed.
For anyone else wanting a workaround until this support is added, it's not pretty but I ended up with this:
locals {
db_srv_records = {
for address in split(",", split("/", mongodbatlas_cluster.cluster.mongo_uri_with_options)[2]) :
replace(split(":", address)[0], "/(cluster[0-9]-shard-[0-9]+-[0-9]+)./", "$1-pri.") => split(":", address)[1]
}
db_txt_record = trimprefix(split("/", mongodbatlas_cluster.cluster.mongo_uri_with_options)[3], "?ssl=true&")
}
This gives you a map in the form of: { server => port, ... }
which you can then iterate over or use keys(db_srv_records)[...]
or values(db_srv_records)[...]
to fetch a specific records hostname or port.
Also related to #183.
@roobert appreciate the share for others! Also note the work is currently in a PR in this repo. We have a bit more to knock out in the next point version but new connections types will be in there.
@themantissa - it would be really useful to expose a map of the cluster shards and a value for the connection settings for those of us that want or need to configure custom DNS, that way we could avoid the string manipulation!
0.5.0 released today now supports all new connection strings as returned attributes: https://www.terraform.io/docs/providers/mongodbatlas/r/cluster.html#connection_strings
In 0.4.0 of the provider, there doesn't appear to be a way to retrieve the privatelink aware mongodb+srv address for my cluster. The
srv_address
attribute of themongodbatlas_cluster
resource returns the same URI as before. When using the Atlas console 'connect' option on the cluster, you can see that there are two different URIs depending on whether you want to use the Privatelink address or the standard address.Here are two URIs for a cluster when PrivateLink is used:
The first is the standard connection address, and the second is the PrivateLink-aware address.
My workaround is to take the value returned by
srv_address
and do areplace()
to get the right address, but this seems fragile.