Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Introduction to Terraform  ›  Lesson

Configuration as Code vs Infrastructure as Code

CaC vs IaC 12 minInfrastructure as code creates the machines, networks and services themselves, while configuration as code sets up the software and files inside machines that already exist.

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.

Sorting Crumb's launch checklistStep 1 of 4
  1. 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.

quick drill

Which job is infrastructure as code?

quick drill

Which tool is mainly a configuration management tool?

quick drill

Crumb's server exists and needs nginx upgraded. Which layer is this?

quick drill

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.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainWhich layer is this?

For Crumb, sort these jobs into infrastructure as code or configuration as code and explain your rule: creating the web server, installing nginx on it, creating the storage bucket, and editing nginx's config file.