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:

Prerequisites

Ensure you have Terraform 1.6+ or OpenTofu installed, along with the juju Terraform provider ~> 2.0.

You must also have a bootstrapped cloud controller and an existing Juju model to deploy into, since these modules deploy into a model rather than creating one.

These modules identify models by UUID rather than by name. Retrieve a model’s UUID with:

juju show-model <model-name> | grep model-uuid

Note

If you’re new to these concepts and vocabulary, check out the Tutorial.

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/product/replica_set/
terraform init
terraform plan -out <filename> -var='model_uuid=<model-uuid>'
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/product/sharded_cluster/
terraform init
terraform plan -out <filename> -var='config_server={"model_uuid": "<model-uuid>", "app_name":"<config-server-name>"' -var='shards=[{"app_name": "<first-shard-name>", "model_uuid": "<model-uuid>"},{"app_name": "<second-shard-name>", "model_uuid": "<model-uuid>"}]' -var='mongos={"model_uuid": "${config_model}","app_name":"<mongos-name>"}' \
terraform apply "<filename>"

See the charms-reference-architectures repository for full, cloud-specific examples of deploying Charmed MongoDB with Terraform, including more integration examples.