Introduction to Terraform
Terraform is an open-source Infrastructure as Code (IaC) software tool created by HashiCorp. It allows users to define and provision a data center infrastructure using a high-level configuration language, automating cloud setups and eliminating manual portal configuration.
The Power of Infrastructure as Code (IaC)
Before IaC, setting up virtual networks, compute instances, and databases required clicking through complex cloud console panels. This was slow and prone to human error. Terraform defines these configurations in code files, which can be versioned, shared, and executed to rebuild identical environments instantly.
Declarative Syntax and State Management
Terraform uses HashiCorp Configuration Language (HCL) to describe the desired final state of your infrastructure. When executed, Terraform reads the configuration, calculates the changes required using a local 'State File' that tracks real resources, and applies only the necessary changes to match the code.
AWS EC2 Infrastructure Provisioning Manifest (HCL)
# Configure provider requirements
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
}
}
}
provider "aws" {
region = "ap-south-1" # Mumbai local region
}
# Deploy an Ubuntu server instance automatically
resource "aws_instance" "pune_staging" {
ami = "ami-03f4878755434977f"
instance_type = "t2.micro"
tags = {
Name = "CACTS-Pune-DevOps-Staging"
}
}
Official Documentation
Access official code repositories and developer documentation.