From d097413340dbac9cd2496ba0628f5d7d0a4219e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martynas=20Petu=C5=A1ka?= Date: Wed, 7 Apr 2021 14:22:36 +0100 Subject: [PATCH] Migration to atlas --- infra/main.tf | 19 ++++++++++++------- infra/outputs.tf | 8 ++++++-- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/infra/main.tf b/infra/main.tf index e15163d..5b95137 100644 --- a/infra/main.tf +++ b/infra/main.tf @@ -75,6 +75,10 @@ resource "mongodbatlas_database_user" "admin" { role_name = "dbAdmin" database_name = local.database_name } + roles { + role_name = "readWrite" + database_name = local.database_name + } } resource "mongodbatlas_database_user" "reader" { @@ -114,12 +118,13 @@ resource "azurerm_app_service_plan" "kamp" { } locals { - database_admin_credentials = "${mongodbatlas_database_user.admin.username}:${mongodbatlas_database_user.admin.password}" - database_reader_credentials = "${mongodbatlas_database_user.reader.username}:${mongodbatlas_database_user.reader.password}" - connection_string_chunks = split("//", data.mongodbatlas_cluster.kamp.connection_strings[0].standard_srv) - connection_string_options = "ssl=true&retryWrites=true&w=majority" - connection_string = "${local.connection_string_chunks[0]}//${local.database_admin_credentials}@${local.connection_string_chunks[1]}/${local.database_name}?${local.connection_string_options}" - database_name = "kamp" + database_admin_credentials = "${mongodbatlas_database_user.admin.username}:${mongodbatlas_database_user.admin.password}" + database_reader_credentials = "${mongodbatlas_database_user.reader.username}:${mongodbatlas_database_user.reader.password}" + connection_string_chunks = split("//", data.mongodbatlas_cluster.kamp.connection_strings[0].standard_srv) + connection_string_options = "ssl=true&retryWrites=true&w=majority" + database_admin_connection_string = "${local.connection_string_chunks[0]}//${local.database_admin_credentials}@${local.connection_string_chunks[1]}/${local.database_name}?${local.connection_string_options}" + database_reader_connection_string = "${local.connection_string_chunks[0]}//${local.database_reader_credentials}@${local.connection_string_chunks[1]}/${local.database_name}?${local.connection_string_options}" + database_name = "kamp" } resource "azurerm_app_service" "kamp" { @@ -154,7 +159,7 @@ resource "azurerm_app_service" "kamp" { DOCKER_REGISTRY_SERVER_URL = var.docker_registry DOCKER_REGISTRY_SERVER_USERNAME = var.docker_registry_username DOCKER_REGISTRY_SERVER_PASSWORD = var.docker_registry_password - MONGO_STRING = local.connection_string + MONGO_STRING = local.database_admin_connection_string MONGO_DATABASE = local.database_name ADMIN_USER = var.api_admin_user ADMIN_PASSWORD = var.api_admin_password diff --git a/infra/outputs.tf b/infra/outputs.tf index 1cb83e8..60f7eb2 100644 --- a/infra/outputs.tf +++ b/infra/outputs.tf @@ -10,12 +10,16 @@ output "mongodbatlas_kamp_reader_credentials" { value = local.database_reader_credentials } +output "mongodbatlas_kamp_reader_connection_string" { + value = local.database_reader_connection_string +} + output "mongodbatlas_kamp_admin_credentials" { value = local.database_admin_credentials sensitive = true } -output "mongodbatlas_connection_string" { - value = local.connection_string +output "mongodbatlas_kamp_admin_connection_string" { + value = local.database_admin_connection_string sensitive = true }