Infrastructure as Code with Terraform [Part 1]
Table of contents
Hello everyone! Today we're gonna learn about Infrastructure as Code with Terraform on AWS cloud. Terraform is easy to learn and once you follow this blog, you'll be good enough to write your own Terraform code. So, let's begin the learning journey.
Introduction:
Terraform is an open-source tool for building, changing, and versioning infrastructure safely and efficiently. It enables users to define their infrastructure as code, meaning that they can write code to automate the process of creating and managing infrastructure resources such as servers, databases, and networks across multiple cloud platforms.
Benefits:
Infrastructure as Code: With Terraform, you can define your infrastructure as code, which means you can create, modify, and version your infrastructure by writing code. This allows for greater consistency, automation, and flexibility in managing your infrastructure.
Multi-Cloud Support: Terraform supports multiple cloud providers, including Amazon Web Services, Google Cloud Platform, Microsoft Azure, and more. This allows you to manage infrastructure resources across different cloud platforms, giving you more flexibility and avoiding vendor lock-in.
Resource Management: Terraform provides a unified way to manage and provision infrastructure resources. It allows you to create, update, and delete resources in a modular and efficient way, which can save you time and effort.
Collaboration: Terraform allows you to collaborate with other developers and operations teams more easily by using version control systems. You can manage your infrastructure code just like your application code, with version control, testing, and deployment processes.
Change Management: Terraform provides a way to track and manage changes to infrastructure resources over time. It enables you to create and apply changes to your infrastructure safely and predictably, reducing the risk of outages or errors.
Terraform working process
Terraform code is written and saved as *.tf files. Once you run the code, the desired infrastructure which you mentioned in the code will be created on the cloud provider end. You can create and destroy the whole infrastructure with a single command!
Installation
Visit the official download page and follow the installation steps to install Terraform on Windows, Linux or another OS.
https://developer.hashicorp.com/terraform/downloads
We'll be installing Terraform on the Ubuntu. Run the following commands and install the Terraform.
wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "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.list
sudo apt update && sudo apt install terraform
Let's check the Terraform version once installed.
> terraform --version
Terraform v1.3.9
You can write Terraform code in vi editor or use a software called Visual Studio Code which I like to use to write Terraform code. It's easy and helpful in organizing .tf files and has lot of inbuilt syntax extentions to integrate with.
You can download and install Visual Studio Code from the below link:
https://code.visualstudio.com/download
Once this is installed, please also install the Hashicorp Terraform extension from the Extension menu.
Cool! Now in the next blog [part 2], we will begin writing our First Terraform code. Stay Tuned, thanks.
Today's top 3 books to read
“When we strive to become better than we are, everything around us becomes better, too.”
― Paulo Coelho, The Alchemist
Aaqib Ahmad
DevOps Engineer