Skip to content

Commit

Permalink
fix: correct repset init for deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
Nico-dl05 committed Dec 2, 2024
1 parent fd25f76 commit 86d15a3
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions terraform/modules/storage/database/mongo/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ resource "docker_container" "database" {
for_each = var.mongodb_params.windows ? [] : [1]
content {
test = ["CMD", "mongosh", "--quiet", "--tls", "--tlsCAFile", "/mongo-certificate/ca.pem", "--eval", "db.runCommand('ping').ok"]
interval = "3s"
interval = "3s"
retries = "2"
timeout = "3s"
}
}

upload {
file = "/mongo-certificate/key.pem"
content = local.server_key
Expand All @@ -39,7 +40,6 @@ resource "docker_container" "database" {
content = tls_locally_signed_cert.mongodb_certificate.ca_cert_pem
}
}

resource "time_sleep" "wait" {
create_duration = var.mongodb_params.windows ? "15s" : "0s"
depends_on = [docker_container.database]
Expand All @@ -54,7 +54,16 @@ locals {

resource "null_resource" "init_replica" {
provisioner "local-exec" {
command = "${local.prefix_run} --eval 'rs.initiate({_id: \"${var.mongodb_params.replica_set_name}\"})'"
command = <<EOT
${local.prefix_run} --eval 'rs.initiate({
_id: "${var.mongodb_params.replica_set_name}",
members: [
{ _id: 0, host: "127.0.0.1:27017" }
]
})'
EOT
}
depends_on = [time_sleep.wait]
}
Expand All @@ -65,4 +74,4 @@ resource "null_resource" "partitions_in_db" {
command = "${local.prefix_run} --eval 'db.PartitionData.insertOne(${jsonencode(each.value)})'"
}
depends_on = [null_resource.init_replica]
}
}

0 comments on commit 86d15a3

Please sign in to comment.