akshaykarle / terraform-provider-mongodbatlas

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

I managed to create the group/user and cluster, but where is the db? #107

Open hilaryRope opened 5 years ago

hilaryRope commented 5 years ago

Hi, apologies if i am a bit of a newbie when it comes to Mongodb atlas and the terraform provider, but I am successfully creating group, user and cluster, but when I inspect my cluster I see no database or collection created, where am I going wrong? Here is some details from my main.tf:

# Create a db user
resource "mongodbatlas_database_user" "mongodb_user" {
  username = "${var.database_username}"
  password = "${random_string.master_password.result}"
  project_id = "${mongodbatlas_project.mongodb.id}"
  database_name  = "admin"

  roles {
    role_name = "readWrite"
    database_name = "admin"
  }
}

group

resource "mongodbatlas_project" "mongodb"{
  org_id = "${var.mongodb_atlas_org_id}"
  name = "${var.project_name}-${var.stage}"
 }

cluster

# Create a cluster
resource "mongodbatlas_cluster" "mongodb-cluster" {
  project_id = "${mongodbatlas_project.mongodb.id}"
  name = "${var.cluster_name}-${var.stage}"
  num_shards = 1

  replication_factor = 3
  backup_enabled = true
  auto_scaling_disk_gb_enabled = true
  mongo_db_major_version = "4.0"

  //Provider Settings "block"
  provider_name = "AWS"
  disk_size_gb = 100
  provider_disk_iops = 300
  provider_encrypt_ebs_volume = false
  provider_instance_size_name = "M40"
  provider_region_name = "us-east-1"
}

I am not sure I follow, but I was under the impression that the db should also be created automatically by terraform inside the cluster?

Thank you so much for your help

Knappek commented 5 years ago

I was confused with that once as well. DB creation is implicit in atlas, just create a role on, say, database_name "myaweesomedb". Collections are implicit as well, just execute a write to a new collection, it will be created automatically if not existing.

Sent with GitHawk

hilaryRope commented 5 years ago

thank you @Knappek, this is much appreciated. What confuses me is that if I go inside the cluster it gives me the option to create a database and from the UI there is no option to delete your existing database (which of course i cannot even see). Does it mean that it is deleted when you remove the cluster and project? I would like to stop the billing too and I am under the impression that as long as i have an existing db that will keep going?! Thanks

Do you also mean that I should create a new role altogether other than the one I have for admin?

Knappek commented 5 years ago

If you delete the cluster, you delete all databases and data inside that cluster (I think you even delete all the backups of not using cloud provider snapshots). Yes absolutely, admin database shouldn't be used, always create specific roles that serve a single purpose following the principle of least privileges.

Sent with GitHawk

Knappek commented 5 years ago

@ilacorda I think you can close this ticket?