Terraform: The essential tool for efficient cloud infrastructure managementšŸ”„

Ā·

4 min read

Terraform: The essential tool for efficient cloud infrastructure managementšŸ”„

Hello Learners, we are doing every task by creating an ec2 instance (mostly). Today letā€™s automate this process. How to do it? Well, Terraform is the solution.

What is Terraform?

Terraform is an infrastructure as code (IaC) tool that allows you to create, manage, and update infrastructure resources such as virtual machines, networks, and storage in a repeatable, scalable, and automated way.

Task-01

Installation of Terraform on your system

Step 1: Launch an instance with Ubuntu AMI, t2.micro instance type, keypair, etc. and then connect it.

Step 2: Go to "https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli" and select Linux. Then copy the below commands.

#To put system up-to-date & verify HashiCorp's GPG signature and install HashiCorp's Debian package repository.
$ sudo apt-get update && sudo apt-get install -y gnupg software-properties-common

#Install the HashiCorp GPG key. 
$  wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg

#Verify the key's fingerprint.
$ gpg --no-default-keyring \
    --keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg \
    --fingerprint

#Add the official HashiCorp repository to your system. 
$ 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

#Again up-to-date the system & install terraform 
$ sudo apt update && sudo apt install terraform

Paste this command on the terminal as shown below.

To check the terraform installation, run this command.

Task-02

Answer the below questions

  1. Why do we use terraform?

    Terraform is an IaC tool used for infrastructure automation that helps manage and provision resources across various cloud platforms and infrastructure providers such as AWS, Azure or GCP.

    You can define the desired state of your infrastructure and let Terraform handle the details of provisioning and updating resources. By using Terraform, you can avoid manual configuration and reduce errors that may arise from human intervention.

    You can also easily version and manage your infrastructure code, making it easier to collaborate and maintain consistency across different environments.

  2. What is Infrastructure as Code (IaC)?

    Infrastructure as Code (IaC) is an approach to managing and provisioning computing infrastructure using code and automation tools instead of manual processes.

    IaC enables organizations to create and manage infrastructure more efficiently and consistently, reducing the likelihood of human error and increasing scalability. It also allows for greater flexibility and agility, as infrastructure can be quickly and easily provisioned, updated, and destroyed as needed.

  3. What is a Resource?

    In Terraform, Resources are the most important element that you want to manage. Each resource block describes one or more infrastructure objects, such as virtual networks, compute instances, storage accounts or higher-level components such as DNS records.

    Resources are a fundamental building block in Terraform, and they enable you to manage your infrastructure as code, with all the benefits that come with it, such as version control, automated testing, and easier collaboration.

  4. What is Provider?

    In Terraform, a provider is a plugin that enables Terraform to interact with a specific infrastructure platform or service, such as Amazon Web Services (AWS), Microsoft Azure, Google Cloud Platform (GCP), or VMware.

    Each provider is responsible for implementing Terraform's resource lifecycle, including resource creation, reading, updating, and deleting.

  5. What is a State file in terraform? Whatā€™s the importance of it?

    In Terraform, a state file is a JSON-formatted file that represents the current state of your infrastructure. It contains information about the resources that have been created, modified, or destroyed using Terraform. The state file is used by Terraform to map the current infrastructure state with the desired state specified in the configuration file.

    The state file is important because,

    Resource management: Terraform's state file tracks created and modified resources to determine which need to be created, updated, or destroyed during configuration changes.

    Concurrency management: The state file in Terraform prevents conflicts when multiple people or systems manage the same infrastructure by allowing only one person or system to modify a resource at a time.

    Rollback management: The state file allows for rolling back to the previous infrastructure state in case of errors or failures during Terraform apply.

  6. What is Desired and Current State?

    In Terraform, the "desired state" is the configuration of the infrastructure that you want to achieve. It's defined in your Terraform code, usually in the form of a configuration file.

    On the other hand, the "current state" is the actual state of your infrastructure as it currently exists. It's what Terraform sees when it inspects the resources in your cloud provider.

    The goal of Terraform is to reconcile the "desired state" with the "current state" of your infrastructure.

Reference: click this video for more details.


Thanks for reading the article with patience.

Keep learning and keep growing.

Stay tuned for the next one.

Ā