What is Terraform? Installation on Ubuntu
Terraform is an open-source Infrastructure as Code (IaC) tool created by HashiCorp. It allows you to define and provision infrastructure resources like virtual machines, networks, storage, and more using declarative configuration files.
Key Features of Terraform:
Declarative Configuration: You describe the desired state of your infrastructure using a simple, human-readable configuration language (HCL).
Multi-Cloud Support: Supports major cloud providers like AWS, Azure, GCP, and many others.
Version Control: Terraform configurations can be versioned in tools like Git, enabling collaboration and tracking changes.
Idempotency: Terraform applies changes in an idempotent manner, ensuring that the desired state is achieved consistently.
State Management: Terraform keeps track of the current state of your infrastructure in a state file.
Getting Started with Terraform:
Create a Terraform configuration file (e.g.,
main.tf
).Define the desired resources in the configuration file.
Initialize the working directory:
terraform init
Plan the changes:
terraform plan
Apply the changes:
terraform apply
Prerequisites
AWS Account with EC2 Instance
2 CPU and 4 GB RAM
Update the system packages.
sudo apt update
Install the wget and unzip packages to download and extract the Terraform setup.
sudo apt-get install wget unzip -y
Install Terraform on Ubuntu
Download the latest Terraform version setup from the Terraform Official Site using wget.
sudo wget https://releases.hashicorp.com/terraform/0.14.7/terraform_0.14.7_linux_amd64.zip
Extract the downloaded setup using the command unzip
.
sudo unzip terraform_0.14.7_linux_amd64.zip
Move the extracted setup to the /usr/local/bin directory.
sudo mv terraform /usr/local/bin/
Verify the Terraform version using the command below.
terraform -v
Output:
Terraform v0.14.7
Check the Terraform commands.
terraform
output:
Terraform v0.14.7
Your version of Terraform is out of date! The latest version
is 1.10.1. You can update by downloading from https://www.terraform.io/downloads.html
By using Terraform, you can automate the provisioning and management of your infrastructure, improve consistency, and reduce the risk of errors.