Understanding Terraform and Ansible
Edited March 2022: Since writing this, I’ve learned a lot. I now strongly recommend to NOT use Ansible from within a provisioner. Instead, run Terraform first and then Ansible second. Or better, use Packer. See Finally understanding why a poor Design Philosophy doomed me to failure
Terraform and Ansible are both Infrastructure as Code (IaC) tools that, together, enable teams to provision and configure virtual resources repeatedly and consistently. Each tool provides different, essential functions of deploying and managing cloud infrastructure: Terraform provisions resources, while Ansible configures resources once they are deployed.
When using Terraform, created by HashiCorp, you declare the end-state you want and the Terraform figures out how to deploy virtual servers, routers, and other resources.
Ansible, by Red Hat, makes changes to existing resources. You provide procedural instructions and Ansible will follow them step-by-step to apply settings to your resources.
This post will give you an understanding of how these two tools can work together. It includes a demo of creating an Nginx proxy on AWS.
Why Infrastructure as Code?
Manually managing routers, servers, firewalls, and every other aspect of a network will produce errors…