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

Unable to connect with amazon documentDB #29

Open
leva0887 opened this issue Sep 15, 2022 · 3 comments
Open

Unable to connect with amazon documentDB #29

leva0887 opened this issue Sep 15, 2022 · 3 comments
Assignees

Comments

@leva0887
Copy link

leva0887 commented Sep 15, 2022

Hello.

I have an issue with connection to AWS DocumentDB

Terraform version:

Terraform v1.1.7
on darwin_amd64

Provider configuration

provider "mongodb" {
      host          = "some_server.eu-central-1.docdb.amazonaws.com"
      port          = "27017"
      username      = "master"
      password      = "password"
      auth_database = "admin"
      insecure_skip_verify = true
      certificate   = file(pathexpand("/Users/some_user/Documents/rds-combined-ca-bundle.pem"))
}

Resource code

resource "mongodb_db_user" "main" {
  auth_database = var.auth_database
  name          = var.username
  password      = random_password.main.result

  dynamic "role" {
    for_each = var.roles

    content {
      role = role.value.role
      db   = role.value.db
    }
  }
}

Terraform plan

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # mongodb_db_user.main will be created
  + resource "mongodb_db_user" "main" {
      + auth_database = "admin"
      + id            = (known after apply)
      + name          = "some_user"
      + password      = (sensitive)

      + role {
          + db   = "admin"
          + role = "readAnyDatabase"
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Error from debug log

2022-09-15T17:19:50.527+0300 [DEBUG] provider: plugin exited
2022-09-15T17:19:50.529+0300 [DEBUG] provider.terraform-provider-mongodb_0.1.5: 2022/09/15 17:19:50 [WARN] Truncating attribute path of 0 diagnostics for TypeSet
mongodb_db_user.main: Creating...
2022-09-15T17:19:50.532+0300 [INFO]  Starting apply for mongodb_db_user.main
2022-09-15T17:19:50.533+0300 [DEBUG] mongodb_db_user.main: applying the planned Create change
mongodb_db_user.main: Still creating... [10s elapsed]
2022-09-15T17:20:00.544+0300 [ERROR] vertex "mongodb_db_user.main" error: Error connecting to database : server selection error: context deadline exceeded, current topology: { Type: ReplicaSetNoPrimary, Servers: [{ Addr: some_server.some_id.eu-central-1.docdb.amazonaws.com:27017, Type: Unknown }, ] }

What am I doing wrong? Please assist

@leva0887
Copy link
Author

Issue found

I have 2 dns
1st - internal VPN dns
2nd - CloudFlare DNS 1.1.1.1

I think provider checks only first DNS which can't resolve DocumentDB host and it's crashes without any attempt to check with 2nd DNS.
After removing 1st DNS it's start working.

@ITMonta
Copy link
Contributor

ITMonta commented Sep 24, 2022

Hello @leva0887 , good to know :)
We can get this error whenthe database deployment has been identified as a [replica set without a primary].

@ITMonta ITMonta self-assigned this Oct 8, 2022
@rastakajakwanna
Copy link

Hello, I've landed here after investigating a similar error and wanted to share another case when this could happen.
Conditions are:

  • you are changing the tls option (in my case it was tls=on -> off) or adding security group (changing basically the reachability of the cluster
  • apply_method is set to "pending-reboot" (cluster or parameter group does not matter, important is that the change is not applied immediately)
  • cluster is unreachable due to this pending change

I know it seems obvious, but it might point someone as tired as me to the right direction after reading this 😃 Cheers and thanks for all the good work on this provider.

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

No branches or pull requests

3 participants