feat(fast/data-mongodb): add MongoDB Atlas database user resource - #4133
feat(fast/data-mongodb): add MongoDB Atlas database user resource#4133suresharam wants to merge 6 commits into
Conversation
accidentally selected approve instead of request changes.
Automated PR Review 🤖(Reviewed commit: 8d32868) Thank you for your contribution! This PR adds useful functionality to the MongoDB Atlas template. I have reviewed the changes against the Cloud Foundation Fabric guidelines. Please address the following points: 1. PR TitleThe current PR title uses Conventional Commits (
Please update the PR title to something like: 2. Variable Design (Map vs Object)Currently, You can use the map key as the
variable "database_users" {
description = "MongoDB Atlas database users configuration."
type = map(object({
auth_database_name = optional(string, "admin")
aws_iam_type = optional(string)
description = optional(string)
labels = optional(map(string), {})
ldap_auth_type = optional(string)
oidc_auth_type = optional(string)
password = optional(string)
password_wo = optional(string)
password_wo_version = optional(number)
roles = optional(
map(object({
collection_name = optional(string)
database_name = string
role_name = string
})),
{}
)
scopes = optional(map(object({
type = string
})), {})
x509_type = optional(string)
}))
default = {}
validation {
condition = alltrue([
for k, v in var.database_users : !(v.password != null && v.password_wo != null)
])
error_message = "Only one of password or password_wo can be set."
}
validation {
condition = alltrue([
for k, v in var.database_users : v.password_wo == null || v.password_wo_version != null
])
error_message = "password_wo_version must be set when password_wo is set."
}
}
resource "mongodbatlas_database_user" "database_user" {
for_each = var.database_users
username = each.key
password = each.value.password
password_wo = each.value.password_wo
password_wo_version = each.value.password_wo_version
project_id = mongodbatlas_project.default.id
auth_database_name = each.value.auth_database_name
aws_iam_type = each.value.aws_iam_type
description = each.value.description
ldap_auth_type = each.value.ldap_auth_type
oidc_auth_type = each.value.oidc_auth_type
x509_type = each.value.x509_type
dynamic "labels" {
for_each = each.value.labels
content {
key = labels.key
value = labels.value
}
}
dynamic "roles" {
for_each = each.value.roles
content {
role_name = roles.value.role_name
database_name = roles.value.database_name
collection_name = roles.value.collection_name
}
}
dynamic "scopes" {
for_each = each.value.scopes
content {
name = scopes.key
type = scopes.value.type
}
}
}3. Documentation UpdatesIf you apply the changes above, please remember to:
Once these changes are applied, a maintainer will do the final review and approval. |
Please address the comments in the automated review above
Summary
Adds MongoDB Atlas database user support to the FAST
data-mongodbproject template.The new
database_uservariable configures amongodbatlas_database_userresource and exposes the configurable fields supported by the underlying provider resource, including authentication settings, roles, scopes, labels, and password handling.Changes
mongodbatlas_database_userto thedata-mongodbtemplate.database_userinput object with support for:usernamepasswordpassword_wopassword_wo_versionauth_database_nameaws_iam_typeldap_auth_typeoidc_auth_typex509_typedescriptionlabelsrolesscopesreadAnyDatabaseonadmin, preserving the template’s simple default behavior.passwordandpassword_wo.password_wo_versionwhenpassword_wois used.~> 2.17sopassword_woandpassword_wo_versionare available.Compatibility
Compared the MongoDB Atlas provider schema for the resources used by this template between
2.7.0and2.17.0. No arguments were removed and no new required arguments were added for the resources used here.The relevant provider changes are additive. The main caveat is that
password_worequires Terraform1.11+.Validation
terraform fmt -check fast/project-templates/data-mongodbpython3 tools/check_documentation.py fast/project-templates/data-mongodbpython3 tools/check_boilerplate.py --scan-files fast/project-templates/data-mongodb/main.tf fast/project-templates/data-mongodb/variables.tf fast/project-templates/data-mongodb/providers_override.tf fast/project-templates/data-mongodb/README.mdterraform -chdir=fast/project-templates/data-mongodb validateChecklist
I applicable, I acknowledge that I have:
terraform fmton all modified filestools/tfdoc.py