In this post, we will take you through the Introduction to Terraform. This post will help you to understand the below topics.
Topics Covered:
- What is Infrastructure as a Code (IaC)?
- List of IaC Tools
- Introduction to Terraform
- Why should we use Terraform and Its Benefits?
- How Terraform works with Key Concepts
- Terraform Installation on Windows & Linux
If you are interested in learning, Request you to go through the below recommended tutorial.
DevOps Full Course Tutorial for Beginners - DevOps Free Training Online
Docker Full Course Tutorial for Beginners - Docker Free Training Online
Kubernetes Full Course Tutorial for Beginners - Kubernetes Free Training Online
Ansible Full Course Tutorial for Beginners - Ansible Free Training Online
Openstack Full Course Tutorial for Beginners - Openstack Free Training Online
Let's Get Started.
You can also watch this entire tutorial on our youtube channel with demo.
What is Infrastructure as a Code (IaC)?
Infrastructure as Code (IaC) helps us to automates the infrastructure provisioning by using codes, scripts or any tools instead of creating the infrastructure manually. Anything you create with codes, files, scripts or using any tools, those will be considered as Infrastructure as Code (IaC).
We can provision, manage or destroy our entire infrastructure using Infrastructure as code (IaC). It enables our organization to completely develop, deploy and scale cloud applications with greater speed, less risk and reduced cost.
List of IaC Tools
Here are some of the most popular IaC Tools:
- Terraform
- AWS CloudFormation
- Azure Resource Manager
- Google Cloud Deployment Manager
- Ansible
- Chef
- Puppet
- SaltStack
- Vagrant
Introduction to Terraform?
Terraform is an open-source infrastructure as code (IaC) tool created by HashiCorp for automating or provisioning infrastructure easily.
Users has to create files, define resources, modules and provision entire data center infrastructure easily, securely and efficiently using declarative configuration language known as HashiCorp Configuration Language (HCL), or optionally JSON.
Even Terraform can manage our existing and any popular service providers as well as custom in house solutions.
Why should we use Terraform and Its Benefits?
- Infrastructure as Code (IaC) - Terraform Manages our entire infrastructure through codes, making our task easier to create, update and destroy it.
- Consistency - Terraform ensure the same configuration defined in terraform files are applied across multiple environments like development, staging and production.
- Automation - Terraform reduces human errors, syntax related issues and manual setup by automating infrastructure provisioning.
- Version Control - Terraform has its inbuilt code tracking feature, so our infrastructure changes will be tracked in code, making easier to review and revert changes at any time.
- Collaboration - Team members can work together on the same infrastructure configurations that improves collaboration from every team members and it increases the productivity.
- Scalability - Using Terraform, We can easily scale our entire infrastructure up or down based on our project requirements.
- Multi-Cloud - Terraform can manage the resources available across any different cloud providers from single terraform configuration.
How Terraform works with Key Concepts
- Create files: Firstly, Create our infrastructure resources in .tf files using HashiCorp Configuration Language (HCL).
- Terraform Init: Execute the command 'terraform init' to initialize the working directory and download the required providers plugins to connect with providers using API.
- Terraform Plan: Execute the command 'terraform plan' to validate and review the changes that is going to be affected before applying any changes. Its like a dry run.
- Terraform Apply: Execute the command 'terraform apply' to apply the desired changes to the infrastructure.
- Review State: Once applied, state files will be created for tracking the desired state. It will hold the current configuration state of the infrastructure.
- Terraform Destroy: Execute the command 'terraform destroy' to completely remove the infrastructure managed by Terraform codes.
Terraform Installation on Windows & Linux
Installing terraform is a straight forward procedure. We have to update the terraform official repository and we can install the terraform packages. I have provided the commands and instruction on how to install terraform on specific platforms.
How to Install Terraform on Ubuntu?
Download terraform gpg key, add terraform repository for the respective ubuntu releases and install terraform.
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpgecho "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.listsudo apt update && sudo apt install terraform
How to Install Terraform on RHEL / CentOS?
Install required dependency packages and update terraform repository to install terraform.
sudo yum install -y yum-utilssudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.reposudo yum -y install terraform
How to Install Terraform on Windows?
Step 1: Use the below official links to download the respective binary files based on your windows platform.
If link not worked, go to Terraform official website and download the respective binary file from the link directly.
Step 2: Unzip the downloaded zip file and copy the executable file to binary locations.
C:\Windows\System32
That's it for this post. Keep practicing and have fun. Leave your comments if any.
0 Comments