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.
| Aspect | Declarative | Imperative |
|---|---|---|
| What the files contain | the desired state | the steps to run |
| Who works out the changes | the tool | a person |
| Running it again | brings the same state | may give a different result |
| Typical tools | Terraform, OpenTofu, Pulumi | bash 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.
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- Terraform documentation: What is Terraform?developer.hashicorp.com/terraform/intro(opens in a new tab)
- Microsoft Learn: What is infrastructure as code?learn.microsoft.com/en-us/devops/deliver/what-is-infrastructure-as-code(opens in a new tab)
- Red Hat: What is infrastructure as code (IaC)?redhat.com/en/topics/automation/what-is-infrastructure-as-code-iac(opens in a new tab)
Verified 8 Nov