https://github.com/lisenet/mongodb-atlas-terraform
MongoDB Atlas cluster deployment with Terraform.
https://github.com/lisenet/mongodb-atlas-terraform
mongodb-atlas terraform
Last synced: 6 months ago
JSON representation
MongoDB Atlas cluster deployment with Terraform.
- Host: GitHub
- URL: https://github.com/lisenet/mongodb-atlas-terraform
- Owner: lisenet
- License: bsd-3-clause
- Created: 2022-08-25T15:00:18.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-02-15T17:54:29.000Z (over 2 years ago)
- Last Synced: 2025-04-02T00:17:44.236Z (7 months ago)
- Topics: mongodb-atlas, terraform
- Language: HCL
- Homepage:
- Size: 81.1 KB
- Stars: 1
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Terraform
These resources should be built with Terraform: https://terraform.io
Create and manage a free tier Mongo Atlas M0 cluster with Terraform.
Note: while you can create an M0 free cluster using the Clusters API resource, you cannot modify an M0 free cluster using the Clusters API resource.
## Pre-requisites
### Install Terraform
On a Debian-based system:
```
sudo apt install -y curl
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
sudo apt update
sudo apt install -y terraform=1.3.4
sudo apt-mark hold terraform
```On a RHEL-based system:
```
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
sudo yum -y install terraform
```### Configure AWS S3 and DynamoDB for Remote State Files
See configuration instructions here:
https://www.lisenet.com/2020/terraform-with-aws-s3-and-dynamodb-for-remote-state-files/
See required IAM account permissions [docs/terraform-aws-iam-permissions.json](./docs/terraform-aws-iam-permissions.json).
### Create API Credentials
You need MongoDB Atlas API credentials that have `Project Owner` permissions in order to deploy a cluster.
Consult MongoDB Atlas documentation for how to create them.
Terraform will read environment variables. You can set the shell to use something like this to avoid being prompted to enter the details:
```
export TF_VAR_mongo_atlas_api_public_key=example
export TF_VAR_mongo_atlas_api_private_key=example
export TF_VAR_mongo_database_admin_password=example
export TF_VAR_mongo_database_app_password=example
```## Deployment
Requires Terraform v1.0 or above.
```
terraform init -upgrade
terraform apply
```Retrieve Mongo Compass connection string:
```
terraform output mongo_compass_connection_string
```
## References
https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs