Provisioning of Atlas Mongodb cluster with terraform for Integration Tests

Hi,
I have tried to provision the cluster to be used later for integration tests with terraform found here (terraform-provider-mongodbatlas/examples/starter at master · mongodb/terraform-provider-mongodbatlas · GitHub) with the following statement (I made a small modification to accept cidr not an ip):

terraform -chdir=“terraform-manifests” apply -state-out=“result.tfstate” -var=“cloud_provider=AZURE” -var=“cluster_name=Foo” -var=“database_name=Bar” -var=“dbuser=test” -var=“dbuser_password=test123$” -var=“cidr_block=0.0.0.0/0” -var=“mongodbversion=5.0” -var=“org_id=MY_ORG_ID” -var=“private_key=MY_PRIVATE_KEY” -var=“project_name=Project 0” -var=“public_key=MY_PUBLIC_KEY” -var=“region=westeurope”

The plan looks ok, but when executing the above apply; I get the following error:

mongodbatlas_project.project: Creating...
╷
│ Error: error creating Project: POST https://cloud.mongodb.com/api/atlas/v1.0/groups: 401 (request "NOT_ORG_GROUP_CREATOR") The currently logged in user does not have the group creator role in organization 6262820f755c87761f7751e8.
│
│   with mongodbatlas_project.project,
│   on project.tf line 1, in resource "mongodbatlas_project" "project":
│    1: resource "mongodbatlas_project" "project" {

Can anyone help with this. Who is the logged in user? I did not logged in anywhere, so I am not sure who is the exception referring to. When I am logged in as a user abc@company.com onto a atlas portal, do I need to assign this user some special permissions, or is the problem somewhere else?

1 Like

The logged-in user is the public API key. Make sure the API key has sufficient permissions for the operation.

Also, M0 clusters are available only for Mongo 4.4 or lower.

Finally, not sure if you are allowed to use the unlimited CIDR range 0.0.0.0/0.

1 Like

Thank you Edgar. I was able to by pass the authentication issues. I had to set permission on the API Key to be “Organization Owner”.

I tried with the following options (I also tried it with ip address as it is on the original github sample instead of cidr_block; but I do not believe this is an issue, since both should work and in cidr_block case I even received an email notification success warning about it; so that think worked and I also see it in the response details):

  1. OPTION:

First I tried with M0 Free cluster (with 4.4 as can be seen on terraform docs). So I have setup the following in terraform files:

cloud_backup = false
auto_scaling_disk_gb_enabled = false
provider_name = var.cloud_provider
provider_instance_size_name = “M0”

-var=“mongodbversion=4.4” (since terraform docs says so)

And I have also setup the Azure region to westeurope. In this case, I get:

mongodbatlas_project.project: Creating…
mongodbatlas_project.project: Creation complete after 5s [id=6262ec38815a200dfa1f42d6]
mongodbatlas_project_ip_access_list.ip: Creating…
mongodbatlas_database_user.user: Creating…
mongodbatlas_cluster.cluster: Creating…
mongodbatlas_database_user.user: Creation complete after 0s [id=YXV0aF9kYXRhYmFzZV9uYW1l:YWRtaW4=-cHJvamVjdF9pZA==:NjI2MmVjMzg4MTVhMjAwZGZhMWY0MmQ2-dXNlcm5hbWU=:dGVzdA==]
mongodbatlas_project_ip_access_list.ip: Creation complete after 4s [id=ZW50cnk=:ODQuMTE1LjIxNi4yNTU=-cHJvamVjdF9pZA==:NjI2MmVjMzg4MTVhMjAwZGZhMWY0MmQ2]

│ Error: error creating MongoDB Cluster: POST …cloud.mongodb.com/api/atlas/v1.0/groups/6262ec38815a200dfa1f42d6/clusters: 400 (request “INVALID_ENUM_VALUE”) An invalid enumeration value M0 was specified.

│ with mongodbatlas_cluster.cluster,
│ on atlas_cluster.tf line 1, in resource “mongodbatlas_cluster” “cluster”:
│ 1: resource “mongodbatlas_cluster” “cluster” {

  1. OPTION:

Then I tried with a different instance size, due to the enum error.

cloud_backup = false
auto_scaling_disk_gb_enabled = false
provider_name = var.cloud_provider
provider_instance_size_name = “M2”

And I have also setup the Azure region to northeurope. (since I saw that M2 is available only in northeurope)

terraform -chdir=“terraform-manifests” apply -state-out=“result.tfstate” -var=“cloud_provider=AZURE” -var=“cluster_name=Foo” -var=“database_name=Bar” -var=“dbuser=test” -var=“dbuser_password=test123$” -var=“cidr_block=0.0.0.0/0” -var=“mongodbversion=4.4” -var=“org_id=my id” -var=“private_key=my key” -var=“project_name=Project_11” -var=“public_key=my key” -var=“region=northeurope”

In this case, I get again:

mongodbatlas_project.project: Creating…
mongodbatlas_project.project: Creation complete after 4s [id=6262f0e8622e084960f1524a]
mongodbatlas_project_ip_access_list.ip: Creating…
mongodbatlas_database_user.user: Creating…
mongodbatlas_cluster.cluster: Creating…
mongodbatlas_database_user.user: Creation complete after 1s [id=YXV0aF9kYXRhYmFzZV9uYW1l:YWRtaW4=-cHJvamVjdF9pZA==:NjI2MmYwZTg2MjJlMDg0OTYwZjE1MjRh-dXNlcm5hbWU=:dGVzdA==]
mongodbatlas_project_ip_access_list.ip: Creation complete after 5s [id=ZW50cnk=:MC4wLjAuMC8w-cHJvamVjdF9pZA==:NjI2MmYwZTg2MjJlMDg0OTYwZjE1MjRh]

│ Error: error creating MongoDB Cluster: POST …cloud.mongodb.com/api/atlas/v1.0/groups/6262f0e8622e084960f1524a/clusters: 400 (request “INVALID_ENUM_VALUE”) An invalid enumeration value M2 was specified

  1. OPTION: Original as it is in the tf example:

cloud_backup = true
auto_scaling_disk_gb_enabled = true
provider_name = var.cloud_provider
provider_instance_size_name = “M10”

-var=“mongodbversion=5.0”

mongodbatlas_project.project: Creating…
mongodbatlas_project.project: Creation complete after 5s [id=6262f160be944a1535c0f66c]
mongodbatlas_project_ip_access_list.ip: Creating…
mongodbatlas_database_user.user: Creating…
mongodbatlas_cluster.cluster: Creating…
mongodbatlas_database_user.user: Creation complete after 1s [id=YXV0aF9kYXRhYmFzZV9uYW1l:YWRtaW4=-cHJvamVjdF9pZA==:NjI2MmYxNjBiZTk0NGExNTM1YzBmNjZj-dXNlcm5hbWU=:dGVzdA==]
mongodbatlas_project_ip_access_list.ip: Creation complete after 6s [id=ZW50cnk=:MC4wLjAuMC8w-cHJvamVjdF9pZA==:NjI2MmYxNjBiZTk0NGExNTM1YzBmNjZj]

│ Error: error creating MongoDB Cluster: POST …cloud.mongodb.com/api/atlas/v1.0/groups/6262f160be944a1535c0f66c/clusters: 500 (request “UNEXPECTED_ERROR”) Unexpected error.

In the last sample, I even tried to turn on the verbose logging in terraform and I got a api call response details (on the one that failed and the rest that were success); but there is not much info there (which makes sense, since it is a good API practice not to disclose an internal exception; but I wish I could see them at least somehow on the portal in some kind of an audit log):
{
“detail”: “Unexpected error.”,
“error”: 500,
“errorCode”: “UNEXPECTED_ERROR”,
“parameters”: [],
“reason”: “Internal Server Error”
}

Any advice is welcome:)

So it seems like you need to use “Atlas Region” EUROPE_NORTH and not Azure Regions for the region part of vars; I found the docs here:

This gives me a more specific error now:

Error: error creating MongoDB Cluster: POST https://cloud.mongodb.com/api/atlas/v1.0/groups/626658bf2740e75cd6e68888/clusters: 402 (request "NO_PAYMENT_INFORMATION_FOUND") No payment information was found for group 626658bf2740e75cd6e68888.

Unfortunately free M0 still does not work due to a enum issues.

Have you followed up with verifying your email yet? When you signed up for a MongoDB Atlas account you should have received an email to do so. If not, please do and then try again.

1 Like

I am having the same problem using terraform… 400 (request "INVALID_ENUM_VALUE") An invalid enumeration value M0 was specified. I have a credit card on file and a valid email.