Bookmarks

IaC — Infrastructure as Code

An approach where servers, networks and cloud resources are described in files, as program code, and managed through version control and automation.

Also: infrastructure-as-code, configuration as code

checked 8 Nov

All terms

Instead of configuring servers by hand in a console, the engineer describes the desired infrastructure state in files, stores them in Git and applies them with a dedicated tool. This makes the infrastructure reproducible: the same description rebuilds the same environment — in a test, in a new region or after a failure.

Declarative and imperative approaches

In the declarative approach, the file describes the end state: “there should be three virtual machines of a given size”. The tool works out on its own what to create, change or delete to bring reality in line with that description. In the imperative approach, the file contains a sequence of commands — “do this, then that”; the author is responsible for the resulting state and the order of steps.

AspectDeclarativeImperative
What the files containthe desired statethe steps to run
Who works out the changesthe toola person
Running it againbrings the same statemay give a different result
Typical toolsTerraform, OpenTofu, Pulumibash scripts, Ansible playbooks

How it works

The description is kept in version control, so every infrastructure change is visible in the history: who changed a load balancer rule or the size of a cluster, when and why. Changes follow the same path as application code: checks, review in a pull request, automated application from a CI/CD pipeline. The tool compares the current infrastructure state with the described one and brings the former to the latter; a mismatch is called configuration drift — it is fixed by applying the description again.

hclTerraform: three identical virtual machines described declaratively
resource "aws_instance" "app" {  ami           = "ami-0abcd1234"  instance_type = "t3.micro"  count         = 3}

Tools

Terraform and its open-source fork OpenTofu describe cloud resources in the HCL language and keep the infrastructure state in a separate state file. Ansible writes server configuration as YAML playbooks and works over SSH without agents. Pulumi lets you describe infrastructure in general-purpose programming languages — Python, TypeScript, Go. The tools are often used together: Terraform creates the networks and machines, Ansible then sets up the software on them.

Sources

the term is written from these pages

Verified 8 Nov

Not to be confused with

what it is mixed up with and how it differs

  • IaaSInfrastructure as a Service

    IaaS is a consumption model: the provider supplies virtual machines and networks. IaC is a way to manage them with code; it works both with IaaS and with your own hardware.

  • GitOps

    GitOps is a practice where Git is declared the single source of state and an agent inside the cluster applies the changes itself; IaC is a more general approach.

  • configuration drift

    Configuration drift is the divergence of the live infrastructure from its description; IaC is exactly what helps find and fix it.

In depth in the references

where the topic is covered in detail

Appears in the references