Infrastructure as Code (IaC) Using Terraform
Infrastructure as Code (IaC) Using Terraform
Infrastructure as Code (IaC) is a practice where infrastructure is provisioned and managed using
code instead of manual processes. Terraform by HashiCorp is a widely-used IaC tool.
Why IaC?
- Version control of infrastructure
- Reusability and automation
- Reduce human errors
Terraform Key Components:
- Provider: Interface to cloud platforms (e.g., AWS)
- Resource: Component to create (e.g., EC2 instance)
- State: Tracks deployed infrastructure
Sample Terraform Code:
provider "aws" {
region = "us-west-2"
}
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
}
Workflow:
1. terraform init Initialize config
2. terraform plan Preview changes
3. terraform apply Apply changes
IaC allows consistent and repeatable provisioning, making infrastructure agile and scalable.