Infrastructure as Code (IaC)

What is Infrastructure as Code (IaC)?

Infrastructure as code (IaC) is the practice of defining and managing computing infrastructure in version-controlled, machine-readable files that automated tools apply, instead of configuring it by hand.

Updated November 2026 · 3 min read


Infrastructure as code (IaC) is the practice of defining and managing computing infrastructure, such as servers, networks, databases, load balancers and permissions, in machine-readable files instead of configuring it by hand. The files are stored in version control, reviewed like application code and applied by automated tools that create or change the infrastructure to match. The same definition can build identical environments for development, testing and production, and every change is recorded.

The practice grew with configuration management tools such as CFEngine (1993), Puppet (2005) and Chef (2009), which automated server setup, and became mainstream with cloud computing, where infrastructure is created through APIs. AWS CloudFormation launched in 2011, HashiCorp's Terraform in 2014 and Pulumi, which uses general-purpose programming languages, in 2018. Kief Morris's book Infrastructure as Code (2016) set out many of the principles teams now follow.

Why It Matters

  • Consistency. Environments built from the same code are the same, which ends "it works in staging" surprises caused by manual differences.
  • Speed. A complete environment can be created in minutes rather than days of tickets and manual work.
  • Traceability. Version control records who changed what, when and why, which helps with troubleshooting and with audit and compliance evidence.
  • Review and testing. Infrastructure changes go through code review and automated checks before they are applied.
  • Recovery. If an environment is lost, it can be rebuilt from code, which supports a disaster recovery plan.

Declarative and Imperative Approaches

DeclarativeImperative
What you writeThe desired end state: "there should be three servers of this size behind a load balancer"The steps to reach it: "create a server, then another, then attach them"
Who works out the stepsThe tool compares desired and actual state and plans the changesThe author
ExamplesTerraform, OpenTofu, CloudFormation, Kubernetes manifestsShell scripts, many Ansible playbooks, SDK scripts

Most modern IaC is declarative, because it handles both creating and updating infrastructure safely and makes the intended state easy to read. Pulumi and the AWS Cloud Development Kit let teams write declarative definitions in languages such as Python or TypeScript.

Key Practices

  • Everything in version control, with changes made only through the code, never by hand in a console.
  • Plan before apply. Tools such as Terraform show exactly what will be created, changed or destroyed before anything happens, and that plan is reviewed.
  • Modules. Reusable, tested building blocks, such as a standard database setup, keep environments consistent. Platform teams often publish them as part of an internal developer platform.
  • Policy as code. Automated rules, written in tools such as Open Policy Agent, block changes that break security or cost policies, such as a publicly readable storage bucket.
  • Drift detection. Regular checks flag any difference between the code and what is actually running, usually caused by manual changes.
  • Immutable infrastructure. Instead of patching running servers, teams replace them with new ones built from updated code.
  • GitOps. A variant in which an automated agent continuously makes the running system match what is in the Git repository.

The Terraform Licensing Change

In August 2023 HashiCorp moved Terraform from an open-source license to the Business Source License, which restricts competing commercial use. In response, a group of companies and contributors created OpenTofu, an open-source fork now hosted by the Linux Foundation. IBM completed its acquisition of HashiCorp in 2025. Both tools remain widely used and largely compatible, but organizations choosing an IaC tool now weigh licensing as well as features.

An Example

Consider a hypothetical retailer whose test environments are built by hand from a wiki page. Each takes about three days, and no two are quite the same. The platform team writes the environment as Terraform modules: network, database, application cluster and monitoring. A new environment now takes about 20 minutes from a pull request, and short-lived environments are created for each feature branch and destroyed when it merges. When an engineer changes a firewall rule by hand during an incident, the nightly drift check flags it the next morning, and the fix is added to the code properly.

Common Pitfalls

  • Manual changes "just this once," which cause drift and get overwritten on the next run.
  • Secrets in code, such as passwords committed to the repository. They belong in a secrets manager.
  • Huge, monolithic configurations where one change risks the whole estate.
  • Applying without reviewing the plan, which is how databases get deleted by accident.
  • Poorly managed state files. Tools such as Terraform track what they manage in a state file that must be stored securely and locked during changes.

IaC is a foundation of DevOps, platform engineering and site reliability engineering, and makes cloud environments easier to govern and to cost through FinOps practices such as consistent tagging.