Infrastructure as Code (IaC)
Infrastructure as Code is the practice of defining servers, networks, databases and other cloud resources in version-controlled files, so a tool can create and change them the same way every time.
Also known as: IaC
How it works
Instead of clicking through a cloud console, engineers write files that describe the resources they need: a network, a Kubernetes cluster, a database, the permissions between them. An IaC tool reads those files, compares them with what already exists and makes the changes needed to match.
There are two broad styles:
- Declarative tools describe the end state and work out the steps. Terraform, OpenTofu, AWS CloudFormation, Azure Bicep, Pulumi and Crossplane follow this model.
- Imperative or procedural tools describe the steps to run. Ansible playbooks and shell scripts are common examples, and are often used for configuring machines rather than provisioning them.
Good IaC is reviewed like application code. A pull request shows a plan of what will change, a teammate reviews it, and a pipeline applies it. Shared modules keep environments consistent, and state files or cloud APIs track what is deployed.
Why it matters
Manually built infrastructure drifts, cannot be reproduced after a failure and has no history of who changed what. IaC makes environments repeatable, so staging matches production and a region can be rebuilt from code. It also lets you run security and cost checks before anything is created. Common pitfalls are unmanaged state files, very large modules that nobody dares to change, and secrets committed to repositories. Gepton covers this in Cloud Infrastructure and IaC.
Infrastructure as Code (IaC) in depth
Example: a reviewed infrastructure change
Example: a hypothetical team needs a new managed PostgreSQL database for a service. An engineer adds a call to the company's shared database module in the service's Terraform configuration, setting size, backup retention and network. Opening a pull request triggers a pipeline that runs formatting and validation, a security scan with a tool such as Checkov or Trivy, a policy check that the database is encrypted and private, and terraform plan. The plan output is posted to the pull request, showing exactly what will be created. A teammate reviews and approves; after merge, the pipeline applies the same plan using short-lived cloud credentials. State is stored in a locked remote backend, and nobody applies changes from a laptop.
Structuring IaC for a growing organization
- Modules: small, versioned building blocks (network, cluster, database) with sensible defaults and few required inputs.
- State boundaries: split state by environment and by component, so a change to one service cannot accidentally touch the shared network, and plans stay fast.
- Environments: the same modules with different inputs, rather than copied code per environment.
- Remote state with locking: object storage plus locking, or a managed backend, with access restricted.
- Automation: plans and applies from a pipeline or a pull-request automation tool such as Atlantis, never from personal machines.
- Drift detection: scheduled plans that alert when the real infrastructure no longer matches code.
Choosing a tool
| Tool | Style | Notes |
|---|---|---|
| Terraform and OpenTofu | Declarative HCL, multi-cloud | Largest provider ecosystem; check license fit (OpenTofu is the open-source fork) |
| AWS CloudFormation, Azure Bicep | Declarative, single cloud | Native integration, no separate state file to manage |
| Pulumi, AWS CDK | General-purpose programming languages | Familiar to developers; discipline needed to keep code declarative |
| Crossplane | Kubernetes custom resources | Fits GitOps and continuous reconciliation |
| Ansible | Procedural configuration | Configuring machines rather than provisioning cloud resources |
Measuring IaC maturity
- Share of cloud resources managed by code, found by comparing cloud inventory with state.
- Drift incidents detected per period.
- Time to create a new environment from scratch.
- Policy violations caught at plan time rather than in production.
Treat modules as products with versions, changelogs and tests. Tools such as Terratest or the native test framework in Terraform and OpenTofu can create real resources in a sandbox account, check them and destroy them, which catches breaking changes before teams upgrade to a new module version.
Common mistakes
- Importing everything into one giant state file.
- Console changes made "just this once" during incidents and never written back.
- Unpinned provider and module versions, so the same code behaves differently next month.
- Secrets as plain variables or in state without encryption and access control.
IaC pairs with policy as code for guardrails, feeds FinOps cost checks before resources are created, and underpins platform engineering. We build and refactor IaC in cloud infrastructure and IaC, on AWS, Azure and Google Cloud.
Questions about Infrastructure as Code (IaC)
Something else? Send us your question and an engineer replies with next steps.
How do we bring existing manually created infrastructure under IaC?
Work incrementally. Inventory what exists, then choose an area with frequent changes or high risk, such as networking or the main database. Terraform and OpenTofu support importing existing resources, including import blocks in configuration, and some tools can generate starting code from live resources. Review the generated code, refactor it into modules, and run plans until they show no changes, which proves code matches reality. Then lock down console access for that area so changes go through code from then on.
Should application developers write infrastructure code?
Often yes, within guardrails. Developers know what their services need, and waiting on a separate team for every database or queue slows delivery. A common model has a platform team maintain well-tested modules and policies, while product teams compose those modules in their own repositories through pull requests that run plans and policy checks automatically. Sensitive shared areas, such as networking and identity, stay with the platform team. This keeps speed and consistency without making everyone an expert in every cloud service.