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.
Deploying MongoDB test environments 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:
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.
Terraform defines the infrastructure and lets us keep track of its state easily. Based on which backend is selected, we can deploy:
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 |
clusters = {<br> "cluster01" = {<br> env_tag = "test"<br> configsvr_count = 3<br> shard_count = 2<br> shardsvr_replicas = 2<br> arbiters_per_replset = 1<br> mongos_count = 3<br> }<br> "cluster02" = {<br> env_tag = "prod"<br> configsvr_count = 5<br> shard_count = 4<br> shardsvr_replicas = 3<br> arbiters_per_replset = 0<br> mongos_count = 3<br> }<br>} |
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.
Once the cloud infrastructure is in place, Ansible handles everything from MongoDB setup to backup configuration:
The playbook approach allows for quick rebuilds and reconfigurations during test cycles.
With this framework, we can quickly test MongoDB features and operational tasks such as:
This approach is ideal for teams considering Percona solutions, doing backup validation, testing schema changes, or simulating disaster recovery.
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 deploying MongoDB test environments, give it a try, and feel free to open issues or pull requests.
Resources
RELATED POSTS