Understanding the Basics of Terraform
To understand a new concept, it’s always good to compare it with something you already know. ( at least this strategy works for me).
I have seen some Ansible scripts that the DevOps team at work used to write. I believe you have heard of Ansible as well.
Ansible is used to deploy apps and configure infrastructure. From a developer's point of view, all the apps we develop are deployed to multiple environments. Infrastructures like AWS or Azure or good old steel servers run our application. Deploying our apps to these infrastructures can be managed using Ansible.
Now lets’ see what Terraform is used for.
Say we need to set up EC2 instances with IAM users with so and so permissions. We can set up this infrastructure using Terraform by declaring what we need. We do not have to manually set up the infrastructure; Terraform will do this for us.
So How is Terraform different from Ansible?
Both tools are available as Infrastructure as a code.
Terraform’s main strength is provisioning the infrastructure, whereas Ansible’s main strength is configuring and managing software updates and deployment.
Terraform Architecture
Terraform architecture has two important components —
Core
Providers
Core
Core components use two inputs —
Configuration file — User-provided configuration file that declares all the requirements.
Data Feeds — Data that helps to maintain details of the current state of the infrastructure.
Providers
This is nothing but technology providers like AWS, Azure, GCP, etc. These providers provide Terraform access to various resources like EC2 etc.
A Basic Terraform Workflow
Write — Write the config file.
Plan — Before applying the changes, terraform will display a plan. At this stage, the plan is reviewed.
Apply — Apply the plan, and Terraform will provision your infrastructure.
I hope we now understand what is Terraform and where it is used.