{"id":22448216,"url":"https://github.com/ridwanbejo/terraform-mongodb-user","last_synced_at":"2026-04-27T12:02:36.068Z","repository":{"id":209105360,"uuid":"723250826","full_name":"ridwanbejo/terraform-mongodb-user","owner":"ridwanbejo","description":"Terraform module for managing MongoDB users and roles","archived":false,"fork":false,"pushed_at":"2023-11-25T13:46:43.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-02T08:27:12.226Z","etag":null,"topics":["automation","devops","hashicorp","hcl","iac","infrastructure-as-code","mongodb","sysadmin","terraform"],"latest_commit_sha":null,"homepage":"","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ridwanbejo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-25T04:20:48.000Z","updated_at":"2024-01-08T02:04:42.000Z","dependencies_parsed_at":"2023-11-25T05:23:07.019Z","dependency_job_id":"d3b507d0-e9b2-4751-8d95-b68479b84507","html_url":"https://github.com/ridwanbejo/terraform-mongodb-user","commit_stats":null,"previous_names":["ridwanbejo/terraform-mongodb-user"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/ridwanbejo/terraform-mongodb-user","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ridwanbejo%2Fterraform-mongodb-user","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ridwanbejo%2Fterraform-mongodb-user/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ridwanbejo%2Fterraform-mongodb-user/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ridwanbejo%2Fterraform-mongodb-user/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ridwanbejo","download_url":"https://codeload.github.com/ridwanbejo/terraform-mongodb-user/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ridwanbejo%2Fterraform-mongodb-user/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32335297,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T23:26:28.701Z","status":"online","status_checked_at":"2026-04-27T02:00:06.769Z","response_time":128,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","devops","hashicorp","hcl","iac","infrastructure-as-code","mongodb","sysadmin","terraform"],"created_at":"2024-12-06T04:21:54.101Z","updated_at":"2026-04-27T12:02:36.053Z","avatar_url":"https://github.com/ridwanbejo.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Terraform MongoDB User\n\nThis is a Terraform module for managing user access at MongoDB. You can use this module both for commercial or non-commercial purposes.\n\nCurrently, you can manage these resources in MongoDB by using this module:\n\n- users\n- roles\n\nTested in:\n\n- MongoDB\n\n## A. Prerequisites\n\nRequirements:\n\n- Terraform with version \u003e= 1.4\n- Kaginari/mongodb\n- Hashicorp/random\n\nBefore we continue to use the module, please pay attention to these terms for `database `in this module:\n\n- `role_db`, selected database for storing role configuration. Default value from tf-provider is `admin`\n- `target_db`, selected database which the privilege will be assigned to.\n- `auth_database`, database that will be used by the user for authentication\n\n## B. How to use this module for your Terraform project ?\n\n- Copy `example/basic-1` project from this module. You can extend it as per your requirements\n- Configure MongoDB host and port by modifying the `providers.tf`. For example `localhost` and `27017`\n  - If you want to use another authentication method, [please read more at the provider documentation](https://registry.terraform.io/providers/Kaginari/mongodb/latest/docs)\n- Configure `TF_VAR_mongodb_username` and `TF_VAR_mongodb_password` as environment variables. For example:\n\n```\n$ export TF_VAR_mongodb_username=root\n$ export TF_VAR_mongodb_password=example\n```\n\n- Check `terraform.tfvars` inside the Project. Please try to see how the variables configured.\n- Adjust the tfvars based on your requirements. The tfvars is just example. Then, Save it\n- Run these commands:\n\n```\n$ terraform init\n$ terraform plan\n```\nThis is the output when you run terraform plan successfully:\n\n```\n...\n\n  # module.tf_mongodb_user.random_password.password[\"septian\"] will be created\n  + resource \"random_password\" \"password\" {\n      + bcrypt_hash      = (sensitive value)\n      + id               = (known after apply)\n      + length           = 16\n      + lower            = true\n      + min_lower        = 0\n      + min_numeric      = 0\n      + min_special      = 0\n      + min_upper        = 0\n      + number           = true\n      + numeric          = true\n      + override_special = \"!#$%\u0026*()-_=+[]{}\u003c\u003e:?\"\n      + result           = (sensitive value)\n      + special          = true\n      + upper            = true\n    }\n\nPlan: 10 to add, 0 to change, 0 to destroy.\n\nChanges to Outputs:\n  + mongodb_roles = {\n      + developer = \"admin\"\n      + guest     = \"admin\"\n    }\n  + mongodb_users = {\n      + bejo    = \"reporting\"\n      + fadjar  = \"reporting\"\n      + ridwan  = \"reporting\"\n      + septian = \"reporting\"\n    }\n\n```\n\nAfter you feel confidence with the terraform plan output, let's apply it.\n\n```\n$ terraform apply -auto-approve\n```\n\n- If it succeed, you must see this kind of output on your terminal\n\n```\n...\n\nmodule.tf_mongodb_user.mongodb_db_role.roles[\"developer\"]: Creation complete after 0s [id=YWRtaW4uZGV2ZWxvcGVy]\nmodule.tf_mongodb_user.mongodb_db_role.roles[\"guest\"]: Creation complete after 0s [id=YWRtaW4uZ3Vlc3Q=]\nmodule.tf_mongodb_user.random_password.password[\"septian\"]: Creation complete after 0s [id=none]\nmodule.tf_mongodb_user.random_password.password[\"bejo\"]: Creation complete after 0s [id=none]\nmodule.tf_mongodb_user.random_password.password[\"fadjar\"]: Creation complete after 0s [id=none]\nmodule.tf_mongodb_user.random_password.password[\"ridwan\"]: Creation complete after 0s [id=none]\nmodule.tf_mongodb_user.mongodb_db_user.users[\"bejo\"]: Creating...\nmodule.tf_mongodb_user.mongodb_db_user.users[\"fadjar\"]: Creating...\nmodule.tf_mongodb_user.mongodb_db_user.users[\"septian\"]: Creating...\nmodule.tf_mongodb_user.mongodb_db_user.users[\"ridwan\"]: Creating...\nmodule.tf_mongodb_user.mongodb_db_user.users[\"bejo\"]: Creation complete after 0s [id=cmVwb3J0aW5nLmJlam8=]\nmodule.tf_mongodb_user.mongodb_db_user.users[\"ridwan\"]: Creation complete after 0s [id=cmVwb3J0aW5nLnJpZHdhbg==]\nmodule.tf_mongodb_user.mongodb_db_user.users[\"septian\"]: Creation complete after 0s [id=cmVwb3J0aW5nLnNlcHRpYW4=]\nmodule.tf_mongodb_user.mongodb_db_user.users[\"fadjar\"]: Creation complete after 0s [id=cmVwb3J0aW5nLmZhZGphcg==]\n\nApply complete! Resources: 10 added, 0 changed, 0 destroyed.\n\nOutputs:\n\nmongodb_roles = {\n  \"developer\" = \"admin\"\n  \"guest\" = \"admin\"\n}\nmongodb_users = {\n  \"bejo\" = \"reporting\"\n  \"fadjar\" = \"reporting\"\n  \"ridwan\" = \"reporting\"\n  \"septian\" = \"reporting\"\n}\n```\n\nYou will see at your MongoDB that users and roles are created once the terraform applied.\n\n## C. Understanding tfvars scenarios\n\nThere are some scenarios that you could choose when using this module. For example:\n\n1. user could be assined without any roles\n\n```\nmongodb_users = [\n  {\n    name          = \"bejo\"\n    auth_database = \"reporting\"\n    roles         = []\n  },\n]\n\n```\n\n2. user could be assigned with default roles (e.g. readAnyDatabase)\n\n```\nmongodb_users = [\n  {\n    name          = \"septian\"\n    auth_database = \"reporting\"\n    roles = [\n      {\n        name    = \"readAnyDatabase\",\n        role_db = \"admin\"\n      }\n    ]\n  },\n]\n\n```\n\n3. user could be assigned with custom roles (e.g. developer)\n\n```\nmongodb_users = [\n  {\n    name          = \"ridwan\"\n    auth_database = \"reporting\"\n    roles = [\n      {\n        name    = \"developer\",\n        role_db = \"admin\"\n      }\n    ]\n  },\n]\n```\n\n## D. Ensuring quality\n\nI am trying to follow these approaches for ensuring quality of the tf-module:\n\n- **validate**, ensure my Terraform module is in correct configuration based on Terraform guideline\n- **auto-format**, ensure my Terraform script is edited with correct format based on Terraform guideline\n- **linter**, ensure my Terraform script is in correct format based on Terraform guideline\n- **security**, ensure my Terraform module is free from CVE and stay compliance\n- **automation**, run all above steps by using automation tool to improve development time and keep best quality before or after merging to Git repository\n\n\nThe tools:\n\n- [terraform validate](https://developer.hashicorp.com/terraform/cli/commands)\n- [terraform fmt](https://developer.hashicorp.com/terraform/cli/commands)\n- [tflint](https://github.com/terraform-lint48ers/tflint)\n- [tfsec](https://github.com/aquasecurity/tfsec)\n- [Pre-commit](https://pre-commit.com/)\n- Github Action [Setup Terraform pipeline](https://github.com/hashicorp/setup-terraform)\n\n## E. How to contribute ?\n\nIf you find any issue, you can raise it here at our [Issue Tracker](https://github.com/ridwanbejo/terraform-mongodb-user/issues)\n\nIf you have something that you want to merge to this repo, just raise [Pull Requests](https://github.com/ridwanbejo/terraform-mongodb-user/pulls)\n\nEnsure that you install all the tools from section D. for development purpose.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fridwanbejo%2Fterraform-mongodb-user","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fridwanbejo%2Fterraform-mongodb-user","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fridwanbejo%2Fterraform-mongodb-user/lists"}