Configuration as Code vs Infrastructure as Code
Crumb's server now exists, created by Terraform. But it is an empty machine: no web server software, no site files. Who installs those? This is where two similar-sounding ideas split apart.
The rule
IaC builds the house; configuration as code furnishes the rooms.
- Infrastructure as code (IaC) creates and changes the platform pieces through a provider's API: servers, networks, load balancers, buckets, DNS records. Terraform, OpenTofu, AWS CloudFormation and Pulumi live here.
- Configuration as code (CaC), often called configuration management, sets up what runs inside existing machines: packages, users, services, config files. Ansible, Chef, Puppet and Salt live here.
The two meet at the server. Terraform creates it:
resource "aws_instance" "web" {
ami = "ami-0123456789abcdef0"
instance_type = "t3.micro"
}Then a configuration tool logs into it and installs nginx, copies the site and starts the service.
The two also treat change differently. Terraform creates, updates or replaces whole platform objects through an API. Configuration tools usually adjust a long-lived machine in place, again and again, which is sometimes called mutable infrastructure. Baking software into a fresh machine image for every change, mentioned below, is the immutable alternative.
The lines blur in practice. Terraform can pass a start-up script to a server, and Ansible has modules that create cloud resources. Many teams also bake software into a ready-made machine image, so a new server needs little configuring at all. But each tool is strongest in its own layer, and "configuration as code" is also sometimes used more loosely for application settings files kept in Git.
The shortcut
Ask "Does the thing exist before this job starts?" If the job creates it, that is IaC. If the job changes what is inside something that already exists, that is configuration as code.
Create the web server
It does not exist yet. IaC: Terraform.
The trap is forcing one tool to do both jobs in depth. Terraform is poor at tracking every package inside a server over time, and configuration tools are clumsy at planning cloud-wide changes.
Drills
Answer fast — trust the rule.
Which job is infrastructure as code?
Which tool is mainly a configuration management tool?
Crumb's server exists and needs nginx upgraded. Which layer is this?
Which statement is most accurate?
Remember
- IaC creates the platform pieces; configuration as code sets up what runs inside them.
- Shortcut: does the thing exist before the job? No means IaC.
- Trap: stretching one tool across both layers in depth.
