Why Infrastructure as Code?
Manually clicking through AWS console to create servers, databases, and networking is error-prone, undocumented, and impossible to reproduce. Infrastructure as Code (IaC) defines your entire cloud setup in version-controlled configuration files.
Terraform Basics
Terraform uses HashiCorp Configuration Language (HCL) to declare resources:
resource "aws_instance" "odoo_server" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t3.medium"
tags = {
Name = "Odoo-Production"
Environment = "production"
}
}
resource "aws_db_instance" "postgres" {
engine = "postgres"
engine_version = "16.2"
instance_class = "db.t3.medium"
allocated_storage = 50
}
Key Benefits
- Version Control: Track every infrastructure change in Git.
- Reproducibility: Create identical staging and production environments.
- Collaboration: Teams review infrastructure changes via pull requests.
- Destroy:
terraform destroytears down everything cleanly.
Getting Started
Install Terraform, configure your cloud provider credentials, write your first main.tf, run terraform init and terraform apply. Start with a simple VPC and single server, then expand.