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

[Bug]: Can't import user database module when both username and auth database user contain hyphens #2876

Open
2 tasks done
conan19842002 opened this issue Dec 10, 2024 · 7 comments
Labels
not_stale Not stale issue or PR

Comments

@conan19842002
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Provider Version

8.0.1

Terraform Version

1.9.8

Terraform Edition

Terraform Open Source (OSS)

Current Behavior

I can't import database user module when both username and auth database name contain hyphens, it does not know which one is which, the following will fail:

terragrunt import 'module.mongodb.mongodbatlas_database_user.user' {project_id}-{username}-{auth_database_name}

Terraform configuration to reproduce the issue

terraform {
  required_providers {
    mongodbatlas = {
      source  = "mongodb/mongodbatlas"
      version = "~> 1.7.0" # Use the latest version or a specific version
    }
  }
}
provider "mongodbatlas" {
  public_key  = var.mongodb_public_key
  private_key = var.mongodb_private_key
}
resource "mongodbatlas_database_user" "user" {
  project_id = mongodbatlas_project.project.id
  username     = var.db_username
  password     = var.db_password
  auth_database_name = "admin"
  roles {
    role_name     = "readWriteAnyDatabase"
    database_name = "admin"
  }
  roles {
    role_name     = "readWrite"
    database_name = var.db_name
  }
}

Steps To Reproduce

Run terragrunt import 'module.mongodb.mongodbatlas_database_user.user' {project_id}-{username}-{auth_database_name}

Logs

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
Copy link
Contributor

Thanks for opening this issue! Please make sure you've followed our guidelines when opening the issue. In short, to help us reproduce the issue we need:

  • Terraform configuration file used to reproduce the issue
  • Terraform log files from the run where the issue occurred
  • Terraform Atlas provider version used to reproduce the issue
  • Terraform version used to reproduce the issue
  • Confirmation if Terraform OSS, Terraform Cloud, or Terraform Enterprise deployment

The ticket CLOUDP-289266 was created for internal tracking.

Copy link
Contributor

This issue has gone 7 days without any activity and meets the project’s definition of "stale". This will be auto-closed if there is no new activity over the next 7 days. If the issue is still relevant and active, you can simply comment with a "bump" to keep it open, or add the label "not_stale". Thanks for keeping our repository healthy!

@github-actions github-actions bot added the stale label Dec 16, 2024
@lantoli lantoli added not_stale Not stale issue or PR and removed stale labels Dec 16, 2024
@shalluin-adeo
Copy link

Got the same issue, and another one, when the database_name contains underscore.
Found out that the regex used to split the database user import ID doesn't allow it :

var re = regexp.MustCompile(`(?s)^([0-9a-fA-F]{24})-(.*)-([$a-z]{1,15})$`)

Shouldn't the regex match the same constraints as those applied when creating the database name ?

@gustavoborragan
Copy link

Same problem whether user or database name or both have hyphens.

@jcframil
Copy link

Same issue here with hyphens. Referring to the regex pattern in the following file:

var re = regexp.MustCompile(`(?s)^([0-9a-fA-F]{24})-(.*)-([$a-z]{1,15})$`)

To address this, consider allowing combinations of letters, $, _, and - in the last segment by updating the regex to:
((?s)^([0-9a-fA-F]{24})-(.*)-([$a-z_\-]{1,15})$)

@gustavoborragan
Copy link

@EspenAlbert
Copy link
Collaborator

This has been merged in #2928
Expecting to have a release out in about 2 weeks. Keeping this open until then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not_stale Not stale issue or PR
Projects
None yet
Development

No branches or pull requests

6 participants