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

How to build an authenticated srv connection string? #115

Open
weberc2-tempus opened this issue Jul 26, 2021 · 0 comments
Open

How to build an authenticated srv connection string? #115

weberc2-tempus opened this issue Jul 26, 2021 · 0 comments

Comments

@weberc2-tempus
Copy link

weberc2-tempus commented Jul 26, 2021

Hello, I'm creating a mongodbatlas_database_user for my application and I'm trying to figure out how to pass my application an authenticated connection string to use, but I can't figure out how to get the host to use to build the connection string. I'm trying something like this:

resource "random_password" "app_mongo_user" {
  length  = 15
  special = true
}

resource "mongodbatlas_database_user" "app" {
  username   = "app"
  password   = random_password.app_mongodb_user.result
  project_id = mongodbatlas_project.this.id

  auth_database_name = "admin"

  roles {
    role_name     = "readWrite"
    database_name = local.mongo_database_name
  }

  scopes {
    name = mongodbatlas_cluster.this.name
    type = "CLUSTER"
  }
}

resource "kubernetes_secret" "app_mongo" {
  metadata {
    name      = "app-mongo"
    namespace = module.workload_context.namespace
  }

  data = {
    MONGO_CONNECTION_STRING = "mongodb+srv://${mongodbatlas_database_user.app.id}:${urlencode(random_password.app_mongodb_user.result)}@${WHAT_GOES_HERE}?retryWrites=true&w=majority"
  }
}

For the WHAT_GOES_HERE placeholder, I'm looking at trying to parse it out of mongodbatlas_cluster.connection_strings.0.standard_srv but that seems really complicated so I assume I must be missing something?

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

1 participant