➡️ An open-source Infrastructure as Code (IaC) program called Terraform enables declarative cloud infrastructure definition, provisioning, and management. You can follow this instructions to set up Terraform step-by-step.🚀

Image description
Step One: Install the terraform
In linux/ Mac:

curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /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

Confirm the installation:

terraform -v

Step 2: Create a Terraform Project
Create a project directory:

mkdir terraform-aws && cd terraform-aws

Initialize a new Terraform project

terraform init

Step 3: Write Your First Terraform Configuration

Terraform configures itself using.tf files. An example main.tf file for setting up an AWS EC2 instance may be found below:

Create main.tf
Step 4: Initial Terraform

provider "aws" {
  region = "us-east-1"
}

resource "aws_instance" "example" {
  ami           = "ami-0c55b159cbfafe1f0" # Change based on your region
  instance_type = "t2.micro"

  tags = {
    Name = "TerraformInstance"
  }
}

To download provider plugins and initialize Terraform, use the following command:

terraform init

Step 5: Plan Infrastructure

Check what changes Terraform will make:

terraform plan

Step 6: Apply Configuration
Provision the resources:

terraform apply -auto-approve

The AWS EC2 instance will be created as a result.

Step 7: Destroy Infrastructure

To delete resources created by Terraform:

terraform destroy -auto-approve

Now you have successfully used Terraform to install infrastructure!