Terraform & Ansible for automated cloud provisioning of a Node.js, MySQL infrastructure on DigitalOcean

Overview

I've been playing with Terraform and Ansible to automate the provisioning of infrastructure and software. Terraform is a powerful tool to automate cloud infrastructure provisioning and versioning (cloud servers, storage, firewalls, etc.), and Ansible helps configure your servers with the right software and environment.

As part of an effort with a couple writers from the DigitalOcean Community team, I created this github repo, which provides a blueprint to quickly set up a two server infrastructure on DigitalOcean, and includes Ansible Playbooks to install node.js, mongodb, nginx, and also an example node application. Ansible also configures the mongodb instance to store data on redundant block storage.

Details

The terraform files included in the repository will provision two servers on DigitalOcean. The first server is used for your web (NGINX) and app (node.js) servers. The second server is for your database (mongodb) server, which will mount a DigitalOcean 100GB Block Storage volume and use it to store data. The architecture looks like this:

In addition to provisioning servers and storage, the terraform configuration files will also define and implement Cloud Firewalls to limit the ports accessible between web, app, and data tiers.

Ansible is then used to download and install recent versions of node.js, nginx, mongodb, and also pull down a repository of a common node.js starter app.

For more info and step-by-step instructions, check out the github repo, or take a look at the community article that describes a few more blueprints.

Happy coding!