Terraform

PankajPankaj
4 min read

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 1:

Install Terraform on your system.

Create an EC2 instance

SSH into your Ubuntu EC2 instance

  • Go to the official Terraform website at https://www.terraform.io/downloads.html.

  • Choose Linux as your operating system and Ubuntu as your package manager.

  • Copy and paste the following three commands into your terminal.

Verify that Terraform is installed correctly by running the following command:
terraform --version

Task 2: Answer below questions

Why do we use terraform?

Terraform is a tool that helps you create, modify, and keep track of your infrastructure safely and consistently. It allows teams to handle infrastructure as they would with code, ensuring it stays exactly as intended. Terraform works with various cloud providers and on-site setups, supporting many types of resources.

What is Infrastructure as Code (IaC)?

Infrastructure as Code (IaC) is a way of handling and setting up infrastructure using code instead of manual steps. With IaC, teams can control and track changes to their infrastructure, automate the setup, and enhance teamwork among different groups. This approach makes it safe and easy to make changes to the infrastructure, reducing the chances of mistakes and inconsistencies.

What is a Resource?

In Terraform, a resource is like a blueprint for a piece of your cloud setup, like a virtual machine or a database. It describes how you want that part of your infrastructure to look. Terraform then uses this description to build, change, or remove that part of the setup as required.

What is a Provider?

In Terraform, a provider is like a connector that talks to a particular cloud service or platform. It tells Terraform what resources are available and how to handle them—whether it's creating, updating, or deleting. Providers are like translators for services, and examples include AWS, Google Cloud, and Microsoft Azure.

What is a State file in Terraform? What’s the importance of it?

The Terraform state file is like a document in JSON format that keeps track of what your infrastructure looks like according to Terraform. It stores details about the resources you've made, their current status, and how they're connected. This file is super important for Terraform—it's what it uses to figure out and carry out changes to your infrastructure. Because it has sensitive info, it's crucial to keep the state file in a safe and secure place.

What is the Desired and Current State?

In Terraform, the desired state is how you want your infrastructure to be, as written in your Terraform files. The current state is the real status of your infrastructure, saved in the Terraform state file. When you use terraform apply, Terraform checks what you want against what's there and adjusts things to match your plans.

Task 3:

Find purpose of basic Terraform commands which you'll use often

  1. terraform init:

    • Purpose: Gets your Terraform environment ready.

    • Details: Downloads needed plugins and sets up the workspace.

  2. terraform init -upgrade:

    • Purpose: Keeps your configuration up to date.

    • Details: Upgrades your configuration for the latest Terraform version.

  3. terraform plan:

    • Purpose: Checks what changes Terraform will make.

    • Details: Displays proposed changes without applying them.

  4. terraform apply:

    • Purpose: Makes changes to your infrastructure.

    • Details: Creates, modifies, or deletes resources to match desired state.

  5. terraform validate:

    • Purpose: Ensures your configuration is correct.

    • Details: Checks for errors and structure issues in your files.

  6. terraform fmt:

    • Purpose: Cleans up your configuration files.

    • Details: Rewrites files for a consistent and readable format.

  7. terraform destroy:

    • Purpose: Clears out all Terraform-created infrastructure.

    • Details: Deletes resources, use with caution to avoid unintended data loss.

What are the main competitors of Terraform?

Certainly, let's provide a distinct paragraph for each tool:

AWS CloudFormation is Amazon Web Services' tool for Infrastructure as Code (IaC). It empowers users to define and manage infrastructure using JSON or YAML templates, offering a streamlined approach to AWS resource control.

Ansible, an open-source IaC tool, simplifies infrastructure management through YAML scripts. It excels in tasks such as provisioning, configuration, and deployment across various platforms, promoting flexibility in automation.

Kubernetes stands out as an alternative to Terraform, focusing on the automated deployment, management, and scaling of containerized applications. It enhances communication and simplifies the handling of containers within applications.

Puppet, an open-source IaC tool, utilizes a declarative language to define and manage infrastructure resources. With a thriving community, Puppet supports a wide range of platforms and cloud providers.

Chef, also open-source, manages infrastructure using Ruby scripts. Well-suited for large-scale setups, Chef offers compatibility with diverse platforms and cloud environments.

Packer serves a unique role, creating identical machine images for multiple platforms from a single configuration source. It is commonly employed to generate standardized images for cloud infrastructure.

Cloud Foundry, an open-source cloud application platform, transforms the app development landscape. It accelerates the building, testing, deployment, and scaling of applications across clouds, frameworks, and programming languages, reducing the complexity associated with infrastructure management.


Thankyou for reading until here. See you in the next one.

0
Subscribe to my newsletter

Read articles from Pankaj directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Pankaj
Pankaj