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
246 stars 177 forks source link

Returning Connection string by endpoint_service_id => not returning connection string as mongodbatlas_privatelink_endpoint_service deployment taking long time #2782

Closed jypa-github closed 1 week ago

jypa-github commented 2 weeks ago

Is there an existing issue for this?

Provider Version

3.112.0

Terraform Version

v1.7.4

Terraform Edition

Terraform Open Source (OSS)

Current Behavior

The private end point connection string is empty. It looks like mongodbatlas_privatelink_endpoint_service deployment takes long time and before that locals block getting executed. Is there any way to return private end point enabled connection string?

something like

value = lookup(mongodbatlas_cluster.main.connection_strings[0].private_endpoint[0].srv_connection_string, azurerm_private_endpoint.main.id)

locals {
private_endpoints = { value = flatten([for cs in data.mongodbatlas_cluster.test.connection_strings : cs.private_endpoint]) } azure_private_endpoint = { value = [for pe in local.private_endpoints.value : pe if contains([for e in pe.endpoints : e.endpoint_id], azurerm_private_endpoint.atlas-group.id)] } azure_srv_connection_string = { value = length(local.azure_private_endpoint.value) > 0 ? local.azure_private_endpoint.value[0].srv_connection_string : "" } }

Terraform configuration to reproduce the issue

I have followed following example from the terraform-provider-mongodbatlas repo.  

https://github.com/mongodb/terraform-provider-mongodbatlas/blob/master/examples/mongodbatlas_privatelink_endpoint/azure/main.tf

The deployement of mongodbatlas_privatelink_endpoint_service tooks 10min

mongodbatlas_privatelink_endpoint_service.pl_link_service: Creation complete after 10m1s

Steps To Reproduce

Run the terraform and see output string Standard connection string is returned but the Private end point enabled string is empty,

Logs

PLConnectionString = ""

Code of Conduct

github-actions[bot] commented 2 weeks ago

Thanks for opening this issue! Please make sure you've followed our guidelines when opening the issue. In short, to help us reproduce the issue we need:

The ticket CLOUDP-283050 was created for internal tracking.

lantoli commented 2 weeks ago

thanks @jypa-github for creating the issue.

I've been trying to reproduce the issue but I've not been able to reproduce it, I always get a non-empty connection string.

Can you try to have a dependency from the cluster to the endpoint_service? something like:

data "mongodbatlas_advanced_cluster" "cluster" {
  count      = var.cluster_name == "" ? 0 : 1
  project_id = var.project_id
  name       = var.cluster_name

 depends_on = [ mongodbatlas_privatelink_endpoint_service.test ]    # try this change
}
lantoli commented 2 weeks ago

hi, note that it's also documented in advanced_cluster documentation: https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/advanced_cluster

Private connection strings are not available until the respective mongodbatlas_privatelink_endpoint_service resources are fully applied. Add a depends_on = [mongodbatlas_privatelink_endpoint_service.example] to ensure connection_strings are available following terraform apply