Skip to content

Infrastructure as code

Infrastructure as code (IaC) means defining servers, networks, databases, permissions and platform configuration in files that live in version control, and letting tools create and change the real infrastructure to match. Changes go through the same workflow as application code: a pull request, a review, automated checks and a pipeline that applies them.

It’s the foundation for almost everything else in modern operations: landing zones, platform engineering, ephemeral test environments and disaster recovery all depend on being able to rebuild infrastructure from code.

Infrastructure changes through a pipeline1. An engineer changes the infrastructure code and opens a pull request. 2. The pipeline shows exactly what will change (the plan), runs tests and checks policy before anyone approves. 3. After approval, the pipeline, not a person, applies the change. 4. Regular drift detection finds manual changes that bypassed the code, so they can be reverted or codified. Engineeredits code Repositorypull request, review Pipelineplan, test, policy Drift detectioncode vs reality Statewhat the tool managesCloud platformsthe real infrastructure1234
Infrastructure changes through a pipeline People change code, not consoles; the pipeline shows the plan, checks policy and applies it.
  1. An engineer changes the infrastructure code and opens a pull request.
  2. The pipeline shows exactly what will change (the plan), runs tests and checks policy before anyone approves.
  3. After approval, the pipeline, not a person, applies the change.
  4. Regular drift detection finds manual changes that bypassed the code, so they can be reverted or codified.
Approach How it works Examples
Declarative provisioning Describe the desired end state; the tool works out the changes Terraform, OpenTofu, AWS CloudFormation, Azure Bicep, Pulumi
Configuration management Configure software on servers to a known state Ansible, Chef, Puppet
Immutable images Build machine or container images once; replace instead of patching Packer, container images
GitOps A controller continuously makes a cluster match what’s in Git Argo CD, Flux
Policy as code Rules checked automatically against every change Open Policy Agent, cloud-native policy services
  • Version control is the source of truth. If it isn’t in the repository, it shouldn’t exist.
  • Plan before apply. Reviewers see the exact diff to real infrastructure, not just the code diff.
  • Pipelines apply, people approve. Humans rarely need write access to production infrastructure; break-glass access is logged and reviewed.
  • Modules as building blocks. A reviewed, versioned module for “a database with backups, encryption and monitoring” lets teams self-serve safely.
  • Separate state per environment and component, stored remotely with locking and encryption, so one change can’t damage everything.
  • Policy as code blocks dangerous changes (public storage, unencrypted databases, missing tags) before they happen.
  • Treat secrets separately. Reference them from a secrets manager; never commit them.
  • Rebuild regularly. Recreating an environment from scratch proves your code is complete, and is the best disaster recovery rehearsal.
  • Repeatable environments: test, staging and production built the same way.
  • Auditability: every change has an author, a review and a history.
  • Recovery: infrastructure can be rebuilt from code after a disaster.
  • Speed and safety together: self-service through reviewed modules and automated checks.
  • A learning curve for teams used to consoles and tickets.
  • State management needs care; a corrupted or shared state file can cause serious damage.
  • Slow feedback for very large stacks, unless they’re split sensibly.

For all production infrastructure, and for any environment that needs to be recreated, audited or kept consistent with others.

Throwaway experiments in a sandbox account can be built by hand. Anything that will last or hold real data should move into code before it does.

  • Click-ops fixes during incidents that never make it back into code, so the next apply undoes them.
  • One huge stack for everything, where every change risks the whole estate.
  • Secrets in the repository.
  • Copy-pasted configuration instead of shared modules, so fixes must be made in fifty places.

Written and edited by Abhinav Taduka, enterprise software architect.