Want to spin up fully functional environments for trying out Percona Server for MongoDB, complete with Percona’s backup and monitoring solutions in minutes? We recently made our automation framework publicly available, which makes it easy to create and manage these environments either on your local machine or in public cloud environments.
Why we built this
Setting up MongoDB clusters manually can be time-consuming and error-prone. To streamline our workflows and enable fast experimentation with real-world setups, we created a flexible, reusable system based on infrastructure as code principles. The solution supports:
- Single-machine deployments (using Docker)
- Cloud-based deployments (AWS, Azure or Google Cloud at the moment)
Different topologies, including multiple sharded clusters, replica sets, and arbiters, are supported. You also get Percona Monitoring and Management (PMM) and Percona Backup for MongoDB (PBM) pre-configured.
Using Terraform to deploy the infrastructure
Terraform defines the infrastructure and lets us keep track of its state easily. Based on which backend is selected, we can deploy:
- Docker: All components on a single machine with MinIO Server for backup storage
- AWS: Each component on a dedicated EC2 instance with backups to an S3 bucket
- GCP: Same as before, with Compute Engine and backups to Cloud Storage
- Azure: Same as before, with Azure VMs and backups to Azure Blob Storage
For the cloud deployments, the VPC, Internet Gateway, Subnets, DNS, and Firewall rules are handled automatically.
Each cluster is defined declaratively in a variable, making it easy to compose complex topologies. Here is a simple example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
clusters = { "cluster01" = { env_tag = "test" configsvr_count = 3 shard_count = 2 shardsvr_replicas = 2 arbiters_per_replset = 1 mongos_count = 3 } "cluster02" = { env_tag = "prod" configsvr_count = 5 shard_count = 4 shardsvr_replicas = 3 arbiters_per_replset = 0 mongos_count = 3 } } |
This is enough to deploy with the default values. Obviously, more things like ports, credentials, etc., can be customized if required.
For the Docker containers option, running Terraform is all you need to do. Percona Docker Images come with everything pre-installed.
For the cloud-based deployments, we don’t use Docker images, so we created an Ansible playbook to install the required packages and complete the installation.
Automating MongoDB installation with Ansible
Once the cloud infrastructure is in place, Ansible handles everything from MongoDB setup to backup configuration:
- Initializing replica sets
- Enabling TLS and secure authentication
- Setting up PMM
- Configuring PBM backups
The playbook approach allows for quick rebuilds and reconfigurations during test cycles.
MongoDB testing made easy
With this framework, we can quickly test MongoDB features and operational tasks such as:
- Replica set failover and recovery
- Sharded cluster behavior
- Point-in-time backups and restore with PBM
- Performance testing
- End-to-end monitoring with PMM
This approach is ideal for teams considering Percona solutions, doing backup validation, testing schema changes, or simulating disaster recovery.
Getting the code
We’ve published this project in a GitHub repository so others can use it or contribute. It’s designed to be cloned, extended, and adapted easily.
Visit the GitHub repository to get started
If you’re looking to simplify your MongoDB testing, training, or CI environments, give it a try, and feel free to open issues or pull requests.