Mongodb Atlas Error with providers

Getting the below error from running TF apply, Plan works okay since its only showing what resources would be provisioned and not interacting with the API

module.mongodb_endpoint["0"].mongodbatlas_privatelink_endpoint_serverless.this[0]: Creating...
╷
│ Error: error adding MongoDB Serverless PrivateLink Endpoint Connection(): https://cloud.mongodb.com/api/atlas/v2/groups/xxxxxx/privateEndpoint/serverless/instance/auto-provisioning-prod/endpoint POST: HTTP 401 Unauthorized (Error code: "") Detail: You are not authorized for this resource. Reason: Unauthorized. Params: []
│
│ with module.mongodb_endpoint["0"].mongodbatlas_privatelink_endpoint_serverless.this[0],
│ on ../../../../modules/auto-provisioning/mongodb_privatelink/endpoint/[main.tf](http://main.tf) line 1, in resource "mongodbatlas_privatelink_endpoint_serverless" "this":
│ 1: resource "mongodbatlas_privatelink_endpoint_serverless" "this" {
│
╵

I am using a data source to get the API keys from AWS secret Manager and passing it to the mongodb atlas

provider “mongodbatlas” {
public_key = data.aws_secretsmanager_secret_version.public_key.secret_string
private_key = data.aws_secretsmanager_secret_version.private_key.secret_string
}

I have tested the API keys using curl command and I can see that they can interact with the Mongodb API endpoints successfully, but just doesnt work in my Terraform script when trying to deploy

Resolved the issue, by refactoring the mongodb provider