akshaykarle / terraform-provider-mongodbatlas

Terraform provider for MongoDB Atlas
Mozilla Public License 2.0
122 stars 54 forks source link

Terraform - 401 you are not authorized for this resource #88

Closed im-dofoborh closed 5 years ago

im-dofoborh commented 5 years ago

Hi All,

I am trying to programmatically create a cluster using your Terraform Provider. Upon queueing of the plan, terraform says :

data.mongodbatlas_project.project: data.mongodbatlasproject.project: Error reading MongoDB Project with name StarWarsDB: MongoDB Atlas: 401 You are not authorized for this resource._

Manifest below:

provider "mongodbatlas" {
  username                = "${var.mongodb_atlas_username}"
  api_key                 = "${var.mongodb_atlas_api_key}"
  version                 = "~> 0.8"
}

# Create a Cluster
# https://github.com/akshaykarle/terraform-provider-mongodbatlas/blob/master/website/docs/r/cluster.html.markdown
data "mongodbatlas_project" "project" {
  name                    = "${var.cluster_project_name}"
}

resource "mongodbatlas_cluster" "cluster" {
  name                    = "${var.cluster_name}"
  group                   = "${data.mongodbatlas_project.project.id}"
  mongodb_major_version   = "${var.mongodb_major_version}"
  provider_name           = "${var.provider_name}"
  region                  = "${var.region}"
  size                    = "${var.data_tier}"
  backup                  = "${var.want_a_backup}"
  disk_gb_enabled         = "${var.enabled_autoscaling}" # by default set to true
  disk_size_gb            = "${var.disk_size_gb}"
}

Note: Within Atlas believe the appropriate API keys to be created and project option to grant public API keys turned on.

I have read API docs also but believe I have made all the necessary changes. Any advice?

im-dofoborh commented 5 years ago

Resolved this. Turns out in MongoAtlas, you have to set API credentials at the cluster level.