How to deploy via Terraform¶
These modules require the Terraform Juju provider. For general Terraform usage, see the official documentation.
Charmed MongoDB offers a base module with core resources: VM | K8s
This includes modules for both replica set and sharded cluster deployments.
These modules support integrations for:
Backups via s3-integrator
Client connections via data-integrator
Monitoring via cos-lite
Encryption via self-signed-certificates
Sharded clusters via the
mongos
router
Prerequisites¶
Ensure you have Terraform 1.8+ or OpenTofu installed.
Deploy a replica set¶
Get access to the replica set product Terraform module code:
git clone https://github.com/canonical/mongodb-operator.git
cd ./mongodb-operator
git clone https://github.com/canonical/mongodb-k8s-operator.git
cd ./mongodb-k8s-operator
Then deploy Charmed MongoDB using Terraform:
cd ./terraform/charm/replica_set/
terraform init
terraform plan -out <filename> -var='model=<model-name>'
terraform apply "<filename>"
Deploy a sharded cluster¶
Get access to the sharded cluster product Terraform module code:
git clone https://github.com/canonical/mongodb-operator.git
./cd mongodb-operator
git clone https://github.com/canonical/mongodb-k8s-operator.git
cd ./mongodb-k8s-operator
Then deploy Charmed MongoDB using Terraform:
cd ./terraform/charm/sharded_cluster/
terraform init
terraform plan -out <filename> -var='config_server={"model": "<model-name>", "app_name":"<config-server-name>"' -var='shards=[{"app_name": "<first-shard-name>", "model": "<model-name>"},{"app_name": "<second-shard-name>", "model": "<model-name>"}]'
terraform apply "<filename>"