I am using the below tf template module to create Mongo DB Atlas private link and connect to the Azure private end point . Pls note I am using a diff module for creating the Mongo Atlas cluster
My problem is every time I do a terraform apply, the Mongo DB Atlas private link is getting destroyed and a new private link is getting created. Is there a way to resolve this . Thanks.
resource "mongodbatlas_privatelink_endpoint" "test" {
project_id = var.project_id
provider_name = "AZURE"
region = "eastus2"
}
resource "azurerm_private_endpoint" "test" {
name = "endpoint-test"
location = data.azurerm_resource_group.test.location
resource_group_name = var.resource_group_name
subnet_id = azurerm_subnet.test.id
private_service_connection {
name = mongodbatlas_privatelink_endpoint.test.private_link_service_name
private_connection_resource_id = mongodbatlas_privatelink_endpoint.test.private_link_service_resource_id
is_manual_connection = true
request_message = "Azure Private Link test"
}
}
resource "mongodbatlas_privatelink_endpoint_service" "test" {
project_id = mongodbatlas_privatelink_endpoint.test.project_id
private_link_id = mongodbatlas_privatelink_endpoint.test.private_link_id
endpoint_service_id = azurerm_private_endpoint.test.id
private_endpoint_ip_address = azurerm_private_endpoint.test.private_service_connection.0.private_ip_address
provider_name = "AZURE"
}
The
mongodbatlas_privatelink_endpoint
resource is still being recreated on everyterraform apply
, even without any changes. This could be due to changes in the state of the resources or the wayTerraform
detects changes.You can verify the
Terraform state
to see if there are any changes detected in themongodbatlas_privatelink_endpoint
resource before runningterraform apply
using below commands.As I don't have a subscription to create a
MongoDB Atlas
cluster for testing, I've used a storage account to check theterraform state show
command.Alternatively, you can also use the
Terraform lifecycle
configuration block to prevent the recreation of themongodbatlas_privatelink_endpoint
on everyterraform apply
.Refer the Stack link related to same issue answered by Me