mongodb / terraform-provider-mongodbatlas

Terraform MongoDB Atlas Provider: Deploy, update, and manage MongoDB Atlas infrastructure as code through HashiCorp Terraform
https://registry.terraform.io/providers/mongodb/mongodbatlas
Mozilla Public License 2.0
240 stars 168 forks source link

Support new private and privateSrv connection strings #183

Closed m-vojvodic closed 4 years ago

m-vojvodic commented 4 years ago

Atlas recently deprecated private IP mode in favor of private connections strings that point to private IP addresses of a cluster. Consequently, the Atlas team added new private and privateSrv fields to the connectionStrings value returned by the public API when there is an active peering connection for the Atlas project:

marko$ curl   --ipv4   -i   -u "username:apiKey"   --digest   "https://cloud.mongodb.com/api/atlas/v1.0/groups/5e332b4eae21dc1b141e3562/clusters/marko-gcp-0"

{"autoScaling":{"compute":{"enabled":false,"scaleDownEnabled":false},"diskGBEnabled":true},"backupEnabled":false,"biConnector":{"enabled":false,"readPreference":"secondary"},"clusterType":"REPLICASET","connectionStrings":{"privateSrv":"mongodb+srv://marko-gcp-0-pri.9pmpk.gcp.mongodb.net","standardSrv":"mongodb+srv://marko-gcp-0.9pmpk.gcp.mongodb.net","private":"mongodb://marko-gcp-0-shard-00-00-pri.9pmpk.gcp.mongodb.net:27017,marko-gcp-0-shard-00-01-pri.9pmpk.gcp.mongodb.net:27017,marko-gcp-0-shard-00-02-pri.9pmpk.gcp.mongodb.net:27017/?ssl=true&authSource=admin&replicaSet=atlas-ixci8a-shard-0","standard":"mongodb://marko-gcp-0-shard-00-00.9pmpk.gcp.mongodb.net:27017,marko-gcp-0-shard-00-01.9pmpk.gcp.mongodb.net:27017,marko-gcp-0-shard-00-02.9pmpk.gcp.mongodb.net:27017/?ssl=true&authSource=admin&replicaSet=atlas-ixci8a-shard-0"},"diskSizeGB":10.0,"encryptionAtRestProvider":"NONE","groupId":"5e332b4eae21dc1b141e3562","id":"5e74e6a343adc0695eac369b","labels":[],"mongoDBMajorVersion":"4.2","mongoDBVersion":"4.2.3","mongoURI":"mongodb://marko-gcp-0-shard-00-00.9pmpk.gcp.mongodb.net:27017,marko-gcp-0-shard-00-01.9pmpk.gcp.mongodb.net:27017,marko-gcp-0-shard-00-02.9pmpk.gcp.mongodb.net:27017","mongoURIUpdated":"2020-03-20T16:01:10Z","mongoURIWithOptions":"mongodb://marko-gcp-0-shard-00-00.9pmpk.gcp.mongodb.net:27017,marko-gcp-0-shard-00-01.9pmpk.gcp.mongodb.net:27017,marko-gcp-0-shard-00-02.9pmpk.gcp.mongodb.net:27017/?ssl=true&authSource=admin&replicaSet=atlas-ixci8a-shard-0","name":"marko-gcp-0","numShards":1,"paused":false,"pitEnabled":false,"providerBackupEnabled":false,"providerSettings":{"providerName":"GCP","autoScaling":{"compute":{"maxInstanceSize":null,"minInstanceSize":null}},"instanceSizeName":"M10","regionName":"CENTRAL_US"},"replicationFactor":3,"replicationSpec":{"CENTRAL_US":{"analyticsNodes":0,"electableNodes":3,"priority":7,"readOnlyNodes":0}},"replicationSpecs":[{"id":"5e74e69843adc0695eac3625","numShards":1,"regionsConfig":{"CENTRAL_US":{"analyticsNodes":0,"electableNodes":3,"priority":7,"readOnlyNodes":0}},"zoneName":"Zone 1"}],"srvAddress":"mongodb+srv://marko-gcp-0.9pmpk.gcp.mongodb.net","stateName":"IDLE","links":[{"href":"https://cloud.mongodb.com/api/atlas/v1.0/groups/5e332b4eae21dc1b141e3562/clusters/marko-gcp-0","rel":"self"},{"href":"https://cloud.mongodb.com/api/atlas/v1.0/groups/5e332b4eae21dc1b141e3562/clusters/marko-gcp-0/restoreJobs","rel":"http://mms.mongodb.com/restoreJobs"},{"href":"https://cloud.mongodb.com/api/atlas/v1.0/groups/5e332b4eae21dc1b141e3562/clusters/marko-gcp-0/snapshots","rel":"http://mms.mongodb.com/snapshots"}]}
"connectionStrings":{
  "privateSrv":"mongodb+srv://marko-gcp-0-pri.9pmpk.gcp.mongodb.net",
  "standardSrv":"mongodb+srv://marko-gcp-0.9pmpk.gcp.mongodb.net",
  "private":"mongodb://marko-gcp-0-shard-00-00-pri.9pmpk.gcp.mongodb.net:27017,marko-gcp-0-shard-00-01-pri.9pmpk.gcp.mongodb.net:27017,marko-gcp-0-shard-00-02-pri.9pmpk.gcp.mongodb.net:27017/?ssl=true&authSource=admin&replicaSet=atlas-ixci8a-shard-0",
  "standard":"mongodb://marko-gcp-0-shard-00-00.9pmpk.gcp.mongodb.net:27017,marko-gcp-0-shard-00-01.9pmpk.gcp.mongodb.net:27017,marko-gcp-0-shard-00-02.9pmpk.gcp.mongodb.net:27017/?ssl=true&authSource=admin&replicaSet=atlas-ixci8a-shard-0"
}

Note that the documentation for these changes is in the process of being published but should be available on pages such as https://docs.atlas.mongodb.com/reference/api/clusters-get-one/ early this week.

The Terraform provider should support the new connection strings to allow users to connect to their clusters via private IP addresses.

themantissa commented 4 years ago

@m-vojvodic thank you very much for submitting this. We plan to address this item in our next round of work, starting in April. We'll tag this issue to the PR when ready so for anyone wanting to keep an eye out on this watch this issue for updates.

themantissa commented 4 years ago

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