mongodbazureapiapi-keyatlas

401 error creating MongoDB Cluster - You are not authorized for this resource


I get the error message in the title when I try to create a cluster with Terraform. I am using API keys to proceed. I whitelisted the IP address and added the ACL to the API key. I ma owner of the project and the organization.

Can anyone help me with this ?

Thank you for your help.


Solution

  • Reason: I was using an old version of the terraform code:

    provider "mongodbatlas" {
      alias       = "mongo_db"
      public_key  = var.public_key
      private_key = var.private_key
    }
    

    But the new version doesn't include the alias line and it fixed the issue when I removed it.

    provider "mongodbatlas" {
      public_key  = var.public_key
      private_key = var.private_key
    }