Terraform : Chapter 1
In this blog we’re gonna talk about Terraform.
Agenda :
- What is Terraform
- What is Terraform used for
- Difference between Terraform and Ansible and when to use each .
- We will also look at the Terraform architecture and commands as well as an example Terraform configuration file
After this we will be having a good overview and understanding of how Terraform actually works and how it does its job.
So first of all what is Terraform?
Terraform allows you to automate and manage your infrastructure, your platform and services that run on that infrastructure. It’s open source and it uses the declarative language, meaning you don’t have to define every step of how these automation and management is done you just declare what you want the final result or end result, and terraform will figure out how to execute it, versus imperative style where you specify how to execute each step.
So as I said terraform is a tool for infrastructure provisioning, so what does it mean exactly?
Let’s say you just started a project where you create some application and you want to set up an infrastructure from scratch where this application will run. how does your infrastructure look like?
Let’s say you want to spin up several servers, where you will deploy your five micro service applications that make up your application as docker containers and also you are going to deploy a database container. You decide to use AWS platform to build your whole infrastructure.
So first step will be to go to AWS and prepare the setup, so the applications can be deployed there. This means you create your private network space, you create an EC2 server instances, install docker on each one and any other tools that you might need for your application, you set up security on your servers like firewalls you set up network etc . Once the infrastructure is prepared you can now deploy your docker applications or docker containers on that prepared infrastructure.
So as you see these are two different tasks or two separate steps of creating the whole setup. One is provisioning the infrastructure preparing everything so the application can be deployed and the second one is actually deploying the applications on it, so you might even have two separate teams or two individuals who do these two separate tasks, so a possible scenario DevOps team member configures the infrastructure and a developer then deploys the applications on the prepared infrastructure.
So where does terraform come into this whole thing?
Terraform is used for the first part, where you provision the infrastructure to prepare it for the application deployment, creating the VPC, spinning up the servers, creating the security, the AWS user with its permissions, installing docker specific version on servers etc and obviously all of this needs to be done in a correct order because one task may be depends on the other.
Now here I must mention something that a lot of people ask when it comes to terraform and that is what is a difference between Ansible and terraform ?which one should I use for my project ?
First of all terraform and Ansible are both infrastructure as a code, meaning they’re both used to automate provisioning, configuring and managing the infrastructure. However Terraform is mainly infrastructure provisioning tool. that’s where its main power lies, but it also has possibilities to deploy applications in other tools on that infrastructure.
Ansibel on the other hand is mainly a configuration tool, so once the infrastructure is provisioned and is it’s there, Ansible can now be used to configure it and deploy applications, install and update software on that infrastructure etc.
Other differences to consider in terms of those overlaps are Ansible is more mature and terraform is relatively new and because of that is also changing dynamically and terraform is more much more advanced in orchestration.
So to summarize the difference, Terraform is a better tool for provisioning infrastructure and Ansible is a better tool for configuring that infrastructure deploying installing applications and services on them.
So it’s a common practice where DevOps engineers use the combination of these tools to cover the whole set up into end using both for their own strengths instead of just using one tool now.
See you in next blog.