Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hilaryRope opened this issue Sep 28, 2019 · 4 comments
Open

Comments

@hilaryRope
Copy link

hilaryRope commented Sep 28, 2019

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
Copy link

Knappek commented Sep 29, 2019

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
Copy link
Author

hilaryRope commented Sep 29, 2019

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
Copy link

Knappek commented Sep 29, 2019

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
Copy link

Knappek commented Oct 3, 2019

@ilacorda I think you can close this ticket?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants