Book a free call

What Is Infrastructure as Code, and When Should You Adopt It?

Infrastructure as code defines servers, networks and cloud resources in versioned files that tools apply automatically, replacing manual setup with repeatable, reviewable changes.

Hertiv engineering teamReviewed by a senior engineer
7 min read
What Is Infrastructure as Code, and When Should You Adopt It?
On this page

Short answer

Infrastructure as code (IaC) is the practice of defining servers, networks, databases and cloud resources in machine-readable files stored in version control, then applying them with tools. It replaces manual console clicks with repeatable, reviewable changes that can be tested and rolled back like application code.

What is infrastructure as code?

Infrastructure as code is the practice of describing servers, networks, storage, permissions and managed cloud services in files that a tool reads and applies, instead of configuring them by hand in a console. The files live in a version control system, so every change has an author, a diff and a history.

The core idea is that infrastructure becomes a software artifact. You can review a change before it happens, run it in a test account first, and rebuild an identical environment from the same source. That matters most when teams grow: a manual setup that one engineer understands becomes an undocumented liability once five people share it.

IaC covers several layers:

  • Provisioning: networks, virtual machines, managed databases, identity and access policies.
  • Configuration: what runs inside a machine, such as packages, services and files.
  • Orchestration: how components connect, including load balancers, DNS and secrets.

Most teams start with provisioning and add configuration management gradually. If your team is moving from a small deployment to a platform others depend on, this work overlaps closely with software engineering services.

Declarative vs procedural: what is the difference?

Declarative tools describe the end state you want; procedural tools describe the steps to reach it. Declarative IaC tools compare what exists against what you declared and make the difference. Procedural tools run your script in order and do whatever it says.

Declarative is usually the better default for cloud infrastructure because it is idempotent: running it twice produces the same result. That makes drift easier to spot. If someone changed a setting manually, the tool shows the difference and can bring the resource back to the declared state.

Procedural scripts remain useful for one-off migrations, data moves or steps that genuinely depend on sequence. The risk is that they encode assumptions. A script written for one account can fail silently in another, and it rarely handles resources that already exist.

A simple comparison:

Aspect Declarative Procedural
Input Desired end state Ordered steps
Repeat safety Idempotent by default Depends on the script
Drift handling Detects and corrects Usually unaware
Best for Cloud resources Migrations, edge cases

Many mature teams combine both: declarative for the steady state, short scripts for transitions. If you need help choosing, an experienced partner can map this to your cloud setup through custom software development engagements.

How do you implement infrastructure as code step by step?

Implement infrastructure as code by starting with one environment, putting state in a shared remote store, and moving changes through the same review process as application code. The sequence below avoids the most common early failures.

  1. Pick one non-critical environment. Choose a development or staging account. Define its network, compute and database resources in code. Leave production alone until the workflow is stable.
  2. Set up remote state. State is the file that records what the tool created. Store it remotely with locking so two engineers cannot apply conflicting changes at once. Encrypt it at rest.
  3. Put the files in version control. Every change becomes a pull request with a diff. Require at least one review for anything touching shared resources.
  4. Add a plan step to CI. Run the tool in plan mode on every pull request and post the output. Reviewers see exactly what will be created, changed or destroyed.
  5. Apply from a controlled pipeline. Do not let engineers apply ad hoc from laptops against production. Use a pipeline with credentials scoped to the target account.
  6. Document modules. Extract repeated patterns into reusable modules with clear inputs. Keep them small and versioned.
  7. Expand environment by environment. Once staging is reliable, repeat for production, then add more accounts or regions.

For teams building platform capabilities alongside product work, devops services and staff augmentation can supply the missing skills without a long hiring cycle.

What problems does IaC solve for growing teams?

Infrastructure as code mainly solves inconsistency, slow recovery and weak change control. Those three problems show up as an organisation adds people, environments and compliance requirements.

Inconsistency. Staging rarely matches production when both are built by hand. Tests pass in one and fail in the other. Declared environments reduce this to configuration differences you can see and fix.

Slow recovery. If a region fails or a resource is deleted, a manual rebuild takes hours or days. An IaC codebase can recreate the environment in the time it takes the tool to run, assuming state and backups are healthy.

Weak change control. Console changes leave no record of who changed what. With IaC, every change has a reviewer and a diff. That helps during audits and incident reviews.

Review friction. Manual provisioning turns infrastructure into a bottleneck. One person holds the knowledge. With code, any engineer can propose a change and have it reviewed.

Example (hypothetical): a team runs three environments and rebuilds staging by hand about twice a month, at roughly half an engineer-day each. That is about one engineer-day per month spent on rebuilds, before counting the delays while people wait. Moving staging to IaC does not remove the work, but it makes the rebuild a single pipeline run.

Which tools are commonly used for infrastructure as code?

The most common IaC tools fall into provisioning, configuration management and packaging categories. Each has a distinct role, and many teams use two of them together.

Provisioning tools create cloud resources. Terraform and OpenTofu are widely used and work across providers. Cloud-native options include AWS CloudFormation, Azure Bicep and Google Cloud Deployment Manager. Pulumi lets teams write infrastructure in general-purpose languages.

Configuration management tools set up what runs inside a server. Ansible, Chef and Puppet are the long-standing options; cloud-init is often used for first-boot setup.

Packaging and templating tools build consistent machine images. Packer is common, and container images often replace machine images for application workloads.

GitOps controllers such as Argo CD and Flux apply Kubernetes manifests from a repository, extending the same model to container platforms.

Choosing between them is less about features and more about fit:

  • If you run multiple clouds, a provider-neutral provisioning tool avoids a rewrite later.
  • If you are deeply committed to one cloud, its native tool integrates tightly with its identity and policy systems.
  • If your engineers prefer typed languages and existing test frameworks, a general-purpose-language tool may reduce context switching.

Whatever you choose, keep the state, secrets and module versions under control. These three decide whether the setup stays maintainable.

What are common mistakes with infrastructure as code?

Common mistakes with infrastructure as code cluster around state, secrets, module sprawl and bypassing the pipeline. Most are organisational rather than technical.

  • Leaving state local or unencrypted. State can contain sensitive values. Store it remotely, encrypt it and restrict access.
  • Committing secrets to the repository. Use a secrets manager and reference values at deploy time. Rotate anything that was ever committed.
  • Letting people apply from laptops to production. Ad hoc applies cause drift and destroy the audit trail. Route production changes through a pipeline.
  • Building giant monolithic configurations. One repository that defines every resource becomes slow and fragile. Split by service or environment boundary.
  • Copy-pasting instead of modules. Duplicated blocks diverge over time. Extract small, tested modules.
  • No plan review. Applying without reading the plan is how production databases get replaced. Make plan output part of the pull request.
  • Skipping the import step for existing resources. Adopting IaC on a live system requires importing resources before managing them, or the tool will try to create duplicates.
  • Ignoring drift. Manual changes still happen. Schedule regular plan runs to detect them.

Security review matters here too; cybersecurity services for product and engineering teams can check that your pipeline credentials and state stores are scoped correctly.

How do you choose between IaC, manual setup and managed platforms?

Choose infrastructure as code when you have more than one environment, more than one engineer touching infrastructure, or compliance requirements that demand a change history. Choose a managed platform when the workload is simple and the provider's defaults fit.

Use these steps to prioritise:

  1. Count the environments. One short-lived environment rarely justifies the setup cost. Three or more usually does.
  2. Check who changes infrastructure. If only one person does, document first. If several do, code and review reduce risk quickly.
  3. Look at recovery needs. If rebuilding a critical environment within a day matters, IaC is the practical route.
  4. Assess compliance pressure. Audit trails, access reviews and change management are easier to satisfy with code in version control.
  5. Estimate the first slice. Pick the smallest useful scope, such as one staging environment, and time it. If the first slice takes weeks, reduce it further.

Managed platforms and IaC are not opposites. Many teams use a managed platform for one layer and IaC for the resources around it. The decision is about where you want control and where you accept provider defaults.

For data-heavy systems, the same principles apply to pipelines and warehouses; data engineering services for analytics and AI often include IaC for those components.

Key takeaways

  • IaC turns infrastructure into versioned files, so every environment change is reviewable and reversible
  • Declarative tools describe the end state; procedural tools describe the steps to get there
  • Start with one non-critical environment and a remote state store before touching production
  • Secrets and state files are the biggest security risks: keep both encrypted and access-controlled
  • IaC is the foundation for repeatable CI/CD, disaster recovery and audit trails

Frequently asked questions

Is infrastructure as code only for cloud environments?

No. IaC applies to on-premises virtualisation, network devices and bare-metal servers as well. Cloud providers made it mainstream because their APIs are consistent, but the same versioned-file approach works anywhere the platform exposes an API or a configuration interface.

Do I need to know a programming language to use IaC?

Most declarative IaC tools use their own configuration language rather than a general-purpose one. You need to understand variables, references and modules, which is closer to reading a structured config than writing an application. Tools that use general-purpose languages require more programming experience.

What is infrastructure drift and why does it matter?

Drift is the difference between what your code declares and what actually exists, usually caused by manual console changes. It matters because future applies may overwrite or conflict with those changes. Regular plan runs detect drift before it causes an incident.

How does IaC affect security and compliance?

It improves both by making every change visible and reviewable. Access policies, network rules and encryption settings become part of the codebase, so they can be checked automatically. The main risks are state files and secrets, which must be encrypted and tightly access-controlled.

Can existing infrastructure be brought under IaC management?

Yes, through an import process. Most tools can read existing resources and record them in state without recreating them. The work is careful and should be done resource by resource, starting with non-critical systems, because an incorrect import can lead to unintended changes.

How long does it typically take to adopt IaC?

A first useful slice, such as one staging environment in code with a plan step in CI, usually takes a few weeks depending on scope. Expanding to production and multiple accounts takes longer. The timeline depends more on team familiarity and existing complexity than on tool choice.

Found this useful? Share it.
Hertiv engineering team

Written from projects we build for clients: software products in production. Every post is reviewed by a senior engineer before publishing and updated when practice changes.

About HertivHow we work

Planning to bring your infrastructure under version control?

A senior engineer replies within one business day. Or see our DevOps service.

Book a free call

Keep reading

All posts

Tell us what you want to build

A senior engineer reads every request and replies within one business day with questions, a rough range, or a call link.

  • NDA on request before any details
  • You own all code, models and IP
  • US, UK and EU time-zone overlap

Your email app should open with your message ready to send. If it does not, write to [email protected].

Prefer email? Write to [email protected]
Estimate costBook a call