Describe servers, networks and databases in files, and let a tool build and change them for you.
Infrastructure as Code (IaC) means you describe your servers, networks, databases and permissions in text files, keep them in Git, and let a tool create and change them. Terraform is the best-known tool for this.
terraform plan shows what would change. terraform apply does it.Before IaC, people built servers by clicking in a cloud console or running a pile of scripts. Nobody could say exactly what was running, two environments slowly became different, and rebuilding after a disaster meant remembering what had been clicked. With IaC, the files are the truth. A pull request is how infrastructure changes, so changes can be reviewed, tested, and rolled back like code.
Terraform reads your files, asks each provider (a plugin for AWS, Azure, Google Cloud, Kubernetes, and many others) what exists, compares that to what you wrote, and builds a plan: a list of things to create, change or destroy. It then calls the cloud APIs in the right order, using the dependencies it found between resources.
resource "aws_instance" "web" {
count = 3
ami = var.image_id
instance_type = "t3.small"
}count from 2 to 3. If the world already has 3, Terraform does nothing. Running it twice gives the same result.| Idea | What it is | Why it matters |
|---|---|---|
| Provider | A plugin that talks to one platform (AWS, Azure, GCP, Kubernetes...) | It is how Terraform reaches the real world |
| Resource | One thing to create: a server, a bucket, a rule | The unit of change in a plan |
| Variables and outputs | Inputs to a configuration, and values it exports | One config, many environments |
| State | A record of what Terraform manages and its real IDs | How plan knows what to change |
| Module | A reusable bundle of resources | Shared, tested building blocks |
| Workspace / environment | A separate state for the same code (dev, staging, prod) | Keeps environments apart |
| Plan and apply | Preview the change, then do it | A safety step before anything breaks |
| Style | Examples | Notes |
|---|---|---|
| Declarative, provisioning | Terraform, OpenTofu, CloudFormation, Pulumi (uses real programming languages) | Describe the end result. Best for creating cloud resources |
| Imperative scripts | Shell scripts, cloud CLI commands | Steps run in order. Easy to start, hard to repeat safely |
| Configuration management | Ansible, Chef, Puppet | Set up software inside machines, often used after provisioning |
A simplified model. Real plans depend on the provider and on which settings can change in place. Here, changing the database engine is shown as a replacement. A hand-made resource that was never in the state is left alone by Terraform.
destroy and -/+ lines. A replaced database or load balancer is the kind of change that causes an outage.| Term | Meaning in easy words |
|---|---|
| Infrastructure as Code | Describing infrastructure in files that a tool applies |
| Declarative | You state the goal, and the tool works out the steps |
| Provider | A plugin that lets Terraform manage one platform |
| Resource | One managed object, such as a server or a bucket |
| State | Terraform's record of what it created and the real IDs |
| Plan | A preview of the changes Terraform will make |
| Apply | Carrying out the plan |
| Drift | Real infrastructure that no longer matches the code |
| Module | A reusable group of resources |
| Workspace | A separate state for the same configuration |
| Blast radius | How much can be harmed by one bad change |
| Idempotent | Running it again changes nothing if nothing is different |
| Choice | We gain | We lose |
|---|---|---|
| One big state | Simple to start | Slow plans, large blast radius |
| Many small states | Safer and faster | Cross-state wiring to manage |
| Apply from CI only | Audited and consistent | Slower emergency fixes |
| Terraform (declarative) | Clear end state | Hard for complex logic |
| Pulumi (real code) | Loops, functions, tests | More power to write confusing code |
-/+ on a database can wipe data.