Definition of infrastructure as code
Infrastructure as code, abbreviated to IaC (sometimes translated in French as infrastructure en tant que code), consists of describing an IT infrastructure in versioned text files, then letting a tool create or modify the resources based on these files. Networks, virtual machines, clusters, databases, access rights or DNS entries are described in this way.
The term is one of common usage. It is among the technical practices grouped under the word DevOps.
What changes when infrastructure is described in files
Without this practice, a resource is created by hand, in a console or by commands entered one by one. Its state is then only known by inspecting what exists.
With versioned files, an infrastructure change takes the form of a modification proposed in a repository. It can be reviewed before being applied. The history shows who changed what and when. An environment can be recreated from the repository, and another built on the same model.
The counterpart is discipline. A change made by hand, outside the files, creates drift: the description and what exists no longer match.
Declarative approach, imperative approach and tools
Common usage distinguishes two approaches. In the declarative approach, the files describe the target state, and the tool works out the operations that lead to it. In the imperative approach, they list the operations to be executed, in order. The boundary is not watertight.
| Tool | What its documentation says |
|---|---|
| Terraform | An infrastructure as code tool with declarative configuration files. It draws up an execution plan, submitted for approval, and tracks the actual infrastructure in a state file |
| OpenTofu | An infrastructure as code tool described in the same terms: declarative configuration, execution plan, state file |
| Pulumi | An infrastructure as code platform that uses general-purpose programming languages (TypeScript, Python, Go, .NET, Java) or YAML. Its engine works out the operations that lead to the desired state expressed by the program |
| Ansible | An open source, agentless automation tool. Its YAML scripts, the playbooks, declare the desired state of a system |
| AWS CloudFormation | A service in which a template describes the AWS resources to be provisioned |
| Bicep | A language with declarative syntax for deploying Azure resources, converted at deployment into an Azure Resource Manager JSON template |
According to the Pulumi documentation, a program is written in a general-purpose language and yet expresses a desired state: the language used is therefore not enough to place a tool in one of the two approaches.
Infrastructure as code, GitOps, delivery pipeline: not to be confused
Infrastructure as code concerns the description of resources. GitOps refers to a way of applying a state described in this manner: according to the principles published by the OpenGitOps project, software agents automatically pull the desired state from its versioned source, continuously observe the actual state and attempt to apply the desired state.
The integration and deployment pipeline is where the files are checked and then applied. The security checks carried out there on infrastructure code fall under DevSecOps.
Finally, platform engineering is an organisation: a dedicated team offers self-service capabilities, which infrastructure as code modules can implement.
Example: a network rule added through a reviewed change
Take a team that needs to allow a new flow to a database. It adds the rule to the file that describes the network and proposes the change in the repository. The tool, of the declarative type, produces a plan: one rule to create, nothing else to modify. A second person reviews the plan, then the delivery pipeline applies it.
Later, this rule is widened by hand in the console, during an incident. The next plan, drawn up from what exists and from the files, reveals the gap. The team then chooses to carry the change over into the files or to restore the described rule.
Shared modules, change review and drift detection are presented on our page on DevOps and platform engineering.