Skip to content

feat(fast/data-mongodb): add MongoDB Atlas database user resource#4058

Open
suresharam wants to merge 1 commit into
GoogleCloudPlatform:masterfrom
suresharam:master
Open

feat(fast/data-mongodb): add MongoDB Atlas database user resource#4058
suresharam wants to merge 1 commit into
GoogleCloudPlatform:masterfrom
suresharam:master

Conversation

@suresharam

Copy link
Copy Markdown

Add MongoDB Atlas database user support to the data-mongodb project template.

A new mongodbatlas_database_user resource is provisioned as part of the template, configured via a new required database_user variable. The user is created with the readAnyDatabase role scoped to the admin database.


Checklist

I applicable, I acknowledge that I have:

  • Read the contributing guide
  • Ran terraform fmt on all modified files
  • Regenerated the relevant README.md files using tools/tfdoc.py
  • Made sure all relevant tests pass

@google-cla

google-cla Bot commented Jul 15, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions

Copy link
Copy Markdown

Automated PR Review 🤖

(Reviewed commit: 2eb0904)

Thank you for your pull request! Here is a review of the changes against the Cloud Foundation Fabric guidelines.

PR Title

The PR title currently uses the Conventional Commits format (feat(fast/data-mongodb): ...), which violates the repository guidelines. Please update the title to use a short, capitalized, imperative format without a trailing dot.
Suggested Title: Add MongoDB Atlas database user resource to fast/project-templates/data-mongodb

Variable Design & Naming

In variables.tf, the database_user object contains attributes named database_user_name and database_user_password. This causes stuttering when referenced (e.g., var.database_user.database_user_name). It is cleaner to simply use name and password.

Opinionated Resource Configuration

In main.tf, the mongodbatlas_database_user resource hardcodes auth_database_name and the roles block. The guidelines state: "don't be too opinionated in resource configurations as this makes it harder for users to implement their exact requirements".

To make this flexible while keeping the common case simple, please expose these as optional attributes in the database_user variable with your current hardcoded values as defaults.

Suggested variables.tf update:

variable "database_user" {
  description = "MongoDB Atlas database user configuration."
  type = object({
    name               = string
    password           = string
    auth_database_name = optional(string, "admin")
    roles = optional(list(object({
      role_name     = string
      database_name = string
    })), [{
      role_name     = "readAnyDatabase"
      database_name = "admin"
    }])
  })
}

Suggested main.tf update:

resource "mongodbatlas_database_user" "database_user" {
  username           = var.database_user.name
  password           = var.database_user.password
  project_id         = mongodbatlas_project.default.id
  auth_database_name = var.database_user.auth_database_name

  dynamic "roles" {
    for_each = var.database_user.roles
    content {
      role_name     = roles.value.role_name
      database_name = roles.value.database_name
    }
  }
}

Documentation

If you apply the variable changes above, please remember to:

  1. Update the database_user block in the README.md examples to use the new name and password keys.
  2. Run python3 tools/tfdoc.py fast/project-templates/data-mongodb to regenerate the variables table.

Once these updates are made, a maintainer will perform the final review and approval.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants