Infrastructure as code (IaC) means describing your servers, networks and databases in text files, then letting a tool build them for you.
Instead of clicking through a cloud console, you get infrastructure you can review and rebuild like any other code.
The problem with clicking
Setting up infrastructure by hand works once. Then someone needs a second environment for testing, or a server dies, and nobody remembers every setting they chose. Small differences creep in between environments, so 'it works in staging' stops meaning 'it works in production'. This is called drift, and it is hard to spot because there is no record of what was meant to be there.
How it works
With IaC you write a file that says what you want, and a tool makes the real infrastructure match it. Most tools are declarative: you describe the end state (two servers, one database, this firewall rule), not the steps to get there. The tool compares your file with what already exists and works out what to create, change or delete.
Here is a small example in Terraform's language, describing one virtual machine on AWS:
resource "aws_instance" "web" {
# placeholder image id
ami = "ami-0123456789abcdef0"
instance_type = "t3.micro"
tags = {
Name = "web-server"
}
}Apply it once and the server is created. Apply it again with nothing changed and nothing happens, because the real world already matches the file. Change t3.micro to t3.small and the tool updates that one server rather than building everything again.
Wondering how this was made? How we make these