-
Notifications
You must be signed in to change notification settings - Fork 208
Open
Labels
Description
Is there an existing issue for this?
- I have searched the existing issues
Provider Version
v2.0.0
Terraform Version
v1.13.3
Terraform Edition
Terraform Open Source (OSS)
Current Behavior
When executing terraform test, I want to mock a data source for a srv connection string.
assert {
condition = data.mongodbatlas_advanced_cluster.mongodb_cluster.connection_strings.private_endpoint[0].srv_connection_string == "mongodb+srv://database-privatelink-0.vvvvvv.mongodb.net"
error_message = "The private endpoint SRV connection string is not correct"
}
I copied the mock data from the actual data source of the cluster.
mock_data "mongodbatlas_advanced_cluster" {
defaults = {
connection_strings = {
private = ""
private_endpoint = [{
connection_string = "mongodb://pl-0-germanywestcentral-azure.vvv.mongodb.net:1024,pl-0-germanywestcentral-azure.vvvv.mongodb.net:1025,pl-0-germanywestcentral-azure.vvvv.mongodb.net:1026/?ssl=true&authSource=admin&replicaSet=atlas-vvvvv-shard-0"
endpoints = [{
endpoint_id = "/subscriptions/vvv/resourceGroups/vvv/providers/Microsoft.Network/privateEndpoints/vvv-mongodb-pe"
provider_name = "AZURE"
region = "GERMANY_WEST_CENTRAL"
}]
srv_connection_string = "mongodb+srv://database-pl-0.vvvvv.mongodb.net"
srv_shard_optimized_connection_string = ""
type = "MONGOD"
}]
private_srv = ""
standard = "mongodb://vvv-shard-00-00.vvvv.mongodb.net:27017,vvv-shard-00-01.vvvv.mongodb.net:27017,vvv-shard-00-02.vvvvv.mongodb.net:27017/?ssl=true&authSource=admin&replicaSet=atlas-vvvv-shard-0"
standard_srv = "mongodb+srv://database.vvv.mongodb.net"
}
}
}
I expected the actual data to mock the data for the test. Sadly the following error pops up:
Error: Failed to compute attribute
│
│ with module.mongodb-config.data.mongodbatlas_advanced_cluster.mongodb_cluster,
│ on ../../modules/mongodb-config/main.tf line 1, in data "mongodbatlas_advanced_cluster" "mongodb_cluster":
│ 1: data "mongodbatlas_advanced_cluster" "mongodb_cluster" {
│
│ Terraform could not compute a value for the target type object with the mocked data defined at tests/mocks/mongodbatlas.tfmock.hcl:8,3-26,4 with the attribute ".connection_strings.private_endpoint": incompatible types; expected object type, found tuple.
It seems like somewhere, its still using the old structure.
If I go back to the old structure, Ill get the following error:
Error: Invalid index
│
│ on ../../modules/mongodb-config/datadog.tf line 2, in locals:
│ 2: node_name = regex("^mongodb://([^:]*)", [for e in data.mongodbatlas_advanced_cluster.mongodb_cluster.connection_strings.private_endpoint : e.connection_string if endswith(e.endpoints[0].endpoint_id, azurerm_private_endpoint.mongodb.name)][0])[0]
│ ├────────────────
│ │ azurerm_private_endpoint.mongodb.name is "crm-lpf-prod-mongodb-pe"
│ │ data.mongodbatlas_advanced_cluster.mongodb_cluster.connection_strings.private_endpoint is empty list of object
│
│ The given key does not identify an element in this collection value: the collection has no elements.
Terraform configuration to reproduce the issue
* Create a MongoDB Cluster in Azure with a private Endpoint
* Do any tests on the private endpoint connection string with a mocked data source
Steps To Reproduce
- Create a MongoDB Cluster in Azure with a private Endpoint
- Do any tests on the private endpoint connection string with a mocked data source
Logs
Code of Conduct
- I agree to follow this project's Code of Conduct