StackLift
All terms

Glossary

Infrastructure as code (IaC)

Managing servers, networks and cloud resources through version-controlled code instead of manual setup.

Infrastructure as code (IaC) is the practice of defining servers, networks, databases and other cloud resources in files that are stored in version control and applied by tools. Instead of clicking through a console, you review, test and deploy infrastructure changes the same way you handle application code.

Common tools include Terraform and OpenTofu, AWS CloudFormation, Pulumi and Azure Bicep. Most work declaratively: you state what should exist, and the tool works out the steps.

The result is repeatable environments, a history of every change and fewer surprises between staging and production.

Start in 60 seconds

Put this to work on your project.

Get an AI-assisted, architect-reviewed scope, cost range, and timeline. Free, no login.

The complete guide

Infrastructure as code (IaC): the complete guide

Updated November 18, 2026 ยท Published by , Founder, StackLift AI. Written with AI assistance; how we make content.

Short answer

Infrastructure as code (IaC) means defining servers, networks, databases and other cloud resources in files kept in version control and applied by tools, instead of clicking through a console. You review, test and deploy infrastructure changes the way you handle application code, which makes environments repeatable and every change traceable.

What is infrastructure as code?

Every application runs on infrastructure: servers or containers, networks, databases, storage, permissions, DNS, queues. Traditionally someone set these up by hand in a cloud console or by logging into machines. The result was a system only that person fully understood.

With infrastructure as code, those resources are described in text files. A tool reads the files, compares them with what exists and makes the changes needed. The files live in Git next to your application, so every change has an author, a reason, a review and a history.

Why does infrastructure as code matter?

Manual setups drift. A setting changed in production during an incident never reaches staging, and nobody remembers why a rule exists. Rebuilding after a failure becomes guesswork. IaC replaces memory with a record.

  • Repeatability: staging and production are built from the same definitions, so they behave alike.
  • Speed: a new environment for a feature, a customer or a test is a command, not a week of tickets.
  • Review: infrastructure changes get pull requests, comments and approvals like code.
  • Recovery: after a failure or a regional outage, you can rebuild from the files.
  • Auditability: Git history answers who changed what and when, which helps with security reviews.
  • Fewer secrets in people's heads: knowledge lives in the repository.

IaC is a natural partner for CI/CD: the same pipeline that tests and ships the application can plan and apply infrastructure changes.

How does infrastructure as code work, step by step?

  1. Describe the resources you want in code: a network, a database, a cluster, a bucket, permissions.
  2. Commit the files to version control and open a pull request.
  3. Run a plan: the tool compares your files with the real environment and shows exactly what it would create, change or destroy.
  4. A teammate reviews the plan along with the code.
  5. Apply the change, ideally through a pipeline and not from a laptop.
  6. The tool records the new state, so it knows what it manages.
  7. Detect drift on a schedule: compare the real environment with the files and flag manual changes.

The plan step is the safety net. It turns an invisible risk, what will this change delete, into a visible diff a person can approve.

What is the difference between declarative and imperative IaC?

Two styles
StyleHow it worksStrengthWatch out for
DeclarativeYou state the end result: there should be a database with these settings; the tool works out the stepsEasy to read, safe to rerunLess room for complex logic
ImperativeYou write the steps in a script or general-purpose languageFull programming powerReruns can have side effects unless written carefully

Most tools are declarative at heart. Some, such as Pulumi and the AWS CDK, let you write in a general-purpose language like TypeScript or Python while still producing a declared end state.

What are the common IaC tools?

Tools compared
ToolWhat it isTypical fit
Terraform and OpenTofuDeclarative, provider-based, works across cloudsMulti-cloud or cloud-neutral teams
AWS CloudFormation and CDKAWS's own templates, with CDK for codeTeams fully on AWS
Azure BicepAzure's declarative languageTeams fully on Azure
PulumiInfrastructure in TypeScript, Python, Go and othersDevelopers who prefer real languages
AnsibleConfigures machines and software, agent-lessServer configuration and orchestration tasks
Helm and KustomizePackage and customize Kubernetes resourcesKubernetes-based deployments
CrossplaneManages cloud resources through Kubernetes APIsPlatform teams standardizing on Kubernetes

Choose the one your team will actually maintain. A cloud-native tool can be simpler if you are committed to one provider. A cloud-neutral tool matters if you may span providers; see AWS vs. Azure for how that decision looks.

What are real-world examples of infrastructure as code?

  • A SaaS team defines a network, a managed PostgreSQL database, a container service and a load balancer, then clones the whole setup for staging.
  • A healthcare software vendor describes access rules and logging in code, so reviewers can see exactly who can reach patient data.
  • A fintech product creates a short-lived test environment for each pull request and destroys it after merge.
  • A logistics platform recreates its stack in a second region to prepare for a regional outage.
  • An agency running many client sites uses one reviewed module to create each client's hosting the same way.
  • A team with a legacy application builds a new cloud landing zone in code before migrating, as in a legacy modernization project.

Each case replaces tribal knowledge with files that anyone with access can read.

How do you adopt infrastructure as code?

  1. Inventory what exists and decide the order: start with new work, then bring in the most painful parts.
  2. Pick a tool and a repository layout, with separate state for each environment.
  3. Store state remotely with locking and encryption, never on a laptop.
  4. Break infrastructure into reusable modules, such as network, database and service.
  5. Run plan on every pull request and require a review before apply.
  6. Apply through a pipeline with limited, role-based credentials, not personal keys.
  7. Add policy checks and security scanning to the pipeline.
  8. Schedule drift detection and treat manual changes as incidents to fix.

Do not try to import everything at once. Bringing a mature environment under code takes time, and a partial, well-run start beats a stalled big bang.

When is infrastructure as code not worth it?

IaC pays back when infrastructure changes, repeats or is shared. A single marketing site on a fully managed platform, with no database and one person editing it, may gain little from a Terraform repository. The overhead of state, pipelines and reviews can exceed the benefit.

  • A throwaway prototype that will be rebuilt or discarded within days.
  • A fully managed, single-environment product with settings already versioned by the platform.
  • A team with no one able to own the tooling, where an unmaintained pipeline becomes its own risk.
  • Experiments where you are still learning what the architecture should be; sketch by hand first, then codify.

Even then, write down the settings you chose and keep the notes in the repository. It is the cheapest first step toward code.

How should environments be organized?

Keep one set of modules and vary them with inputs. A typical layout has development, staging and production, each with its own state and credentials, built from the same modules with different sizes and settings. Staging should be close enough to production that a successful change there predicts success in production.

Promote changes the way you promote application code: merge, apply to staging, verify, then apply to production with approval. Pair this with a rollback plan, such as reverting the commit and applying again, and with blue-green deployments or canary releases for the application layer.

How does IaC affect security?

It helps and it creates new duties. On the plus side, permissions, network rules and encryption settings become visible and reviewable, and scanners can flag risky patterns before anything is created. On the other side, the pipeline that applies infrastructure holds powerful credentials, and state files can contain sensitive values.

  • Keep secrets in a secrets manager, never in the repository or plain state.
  • Use short-lived, least-privilege credentials for the pipeline.
  • Protect the state store with encryption, access control and versioning.
  • Scan code for misconfigurations such as open storage or wide-open network rules.
  • Require approval for changes to production and to identity and access settings.

See the security review checklist and the security page for how StackLift treats these controls.

What are the common IaC mistakes?

Mistakes and fixes
MistakeWhat happensFix
Applying from a laptopNo review, no record, inconsistent versionsApply only through a pipeline
One giant state for everythingSlow plans, high blast radiusSplit by environment and by component
Secrets in code or stateCredentials leakUse a secrets manager and mark values sensitive
Manual changes in the consoleDrift, and the next apply undoes themDetect drift and route changes through code
Copy-pasted environmentsStaging and production divergeShared modules with per-environment variables
No review of the planA destroy slips throughRequire plan review, protect critical resources
Untested modulesA change breaks many environmentsTest modules in a sandbox before releasing

How do you know your IaC is working?

Look for outcomes. Can you build a new environment from scratch without help? Do staging and production differ only by variables? Is any change made outside Git? How long does it take to recover from a lost environment, and have you tested it?

Track drift findings over time, the share of infrastructure under code, how long reviews and applies take, and how often infrastructure changes cause incidents. These sit alongside deployment measures such as lead time and rollback frequency, and feed your observability and service level objectives.

What does infrastructure as code mean for cost and timeline?

Setting it up for a new project is usually modest, because modules and pipelines are written as part of the first sprints. Bringing an existing, hand-built environment under code costs more, since someone must discover what exists, decide what to keep and import it safely.

Effort grows with the number of environments, clouds, regions, compliance controls and services. Savings come from faster environment creation, fewer outages from drift and shorter recovery. See the cloud and DevOps cost page and the free estimate.

How StackLift approaches infrastructure as code

StackLift treats infrastructure as part of the scope, not an afterthought. CI/CD, observability, security review and rollback are in the plan from sprint one, and an architect reviews the design before work begins.

Agents work on feature branches and never touch production secrets, and engineers own the decisions and approve changes. See production readiness and delivery operations.

Questions people ask

What does infrastructure as code mean in simple terms?

It means describing your servers, networks and databases in files instead of setting them up by hand. A tool reads the files and builds or updates the real thing to match.

What is the most popular IaC tool?

Terraform, and its open-source fork OpenTofu, are widely used across clouds. AWS CloudFormation, Azure Bicep and Pulumi are common alternatives. The right choice depends on your cloud and team.

Is Terraform the same as infrastructure as code?

No. Terraform is one tool for doing infrastructure as code. IaC is the practice, and several tools support it.

What is configuration drift?

Drift is when the real environment no longer matches its code, usually because someone changed it by hand. Regular drift checks catch it before it causes surprises.

Do small projects need infrastructure as code?

A tiny site on a managed platform may not. Once you have more than one environment, a database, or several people changing infrastructure, the benefits show up quickly.

What is GitOps?

GitOps is a way of operating systems where Git is the source of truth and a controller keeps the live environment matching it. It extends IaC with automatic reconciliation.

Is IaC secure?

It can improve security by making rules reviewable and scannable, but it needs care with secrets, state files and the pipeline's own credentials.

How long does it take to adopt IaC?

For a new project it can be part of the first sprints. For an existing hand-built environment it is a gradual effort, done piece by piece. The free estimate can scope it for your situation.

Sources

Sources and further reading

The standards, rules, research and official documentation this page draws on.