LIVEยทThe trends shaping tomorrow's world.
Future Tech

Infrastructure as Code Explained

How infrastructure as code works: declarative config, state, plan and apply, drift, and how Terraform, OpenTofu, CloudFormation and Pulumi compare.

Infrastructure as code (IaC) means defining servers, networks, databases and permissions in text files, then letting a tool create and change the real resources to match. Those files live in version control like application code, so every change can be reviewed, repeated and rolled back [1]. Terraform, OpenTofu, AWS CloudFormation and Pulumi are the best-known tools, and they all share one core loop: describe the desired end state, preview the difference, then apply it.

The problem IaC solves

Before IaC, teams built infrastructure by clicking through consoles or running scripts and runbooks by hand. AWS's DevOps whitepaper describes the failure mode well: the person who writes a runbook often isn't the person who follows it, scripts go stale, and new environments end up not "repeatable, reliable, or consistent" [1].

IaC applies the discipline of software development to infrastructure. AWS's summary is that configurations "should be defined in a declarative way and stored in a source control system," the same as application code [1]. Once infrastructure is text, you get the things developers already rely on: a change history, peer review, automated tests and the ability to recreate an environment from scratch.

A useful analogy is a building's blueprint versus a list of construction instructions. A blueprint says what the finished building looks like. A competent contractor works out the order of the steps. Declarative IaC is the blueprint.

How infrastructure as code works

Most IaC tools follow the same four-part model, though they name the parts differently.

1. Configuration: the desired state

You write files that describe resources and their settings. HashiCorp's documentation is explicit that Terraform configuration "is declarative, meaning that they describe the end state of your infrastructure" [2]. A minimal Terraform resource looks like this:

resource "aws_s3_bucket" "logs" {
bucket = "example-logs-bucket"
}

You don't write "call the create-bucket API." You say a bucket with this name should exist, and the tool decides whether that means creating, updating or doing nothing.

2. Providers: the bridge to real APIs

The tool itself doesn't know how to talk to every cloud. Plugins do. In Terraform, providers "enable Terraform to work with virtually any platform or service with an accessible API" [2]. Pulumi uses the same idea: its deployment engine asks a resource provider plugin to perform each operation rather than calling the cloud API directly [13].

3. State: the tool's memory

To know what to change, the tool must remember what it already built. Terraform keeps a state file that "acts as a source of truth for your environment" and maps real resources to your configuration [2][3]. By default that file is a local terraform.tfstate; HashiCorp recommends a remote backend or HCP Terraform for teams, with locking and access control [3]. Pulumi also records each resource it creates in a state file, stored by default in Pulumi Cloud or in self-managed backends such as Amazon S3, Azure Blob Storage, Google Cloud Storage or a local filesystem [13][14].

CloudFormation handles this differently. AWS manages the record of what belongs to each stack, a collection of resources that you create, update and delete as a single unit [9].

4. Plan, then apply

The defining habit of IaC is previewing before changing. Terraform's workflow is Write, Plan, Apply. During planning it reads the current state of remote objects, compares them to the configuration, and proposes actions; terraform plan "alone does not actually carry out the proposed changes" [4]. Only after approval does apply make the changes, in dependency order, with independent resources handled in parallel [2].

CloudFormation's equivalent is the change set. You submit a modified template, CloudFormation shows which resources will be added, modified or deleted, and nothing happens until you execute it [10]. Pulumi's engine computes "the set of operations needed to drive the current state of your infrastructure into the desired state," deciding for each resource whether to create, update in place, replace or delete it [13].

Declarative vs imperative, and where Pulumi fits

There are two broad ways to describe infrastructure:

  • Declarative: you state the end result (Terraform's HCL, CloudFormation's JSON or YAML templates).
  • Imperative: you write the steps (a shell script that calls APIs in order).

The interesting middle ground is general-purpose programming languages that produce a declarative result. Pulumi programs can be written in TypeScript, JavaScript, Python, Go, C#, Java, YAML or HCL; a "language host" runs your program, which registers resources with the engine, and the engine then works out the diff against prior state [13]. AWS's Cloud Development Kit (CDK) takes a similar approach for AWS: you write TypeScript, JavaScript, Python, Java, C# or Go, and the CDK deploys through CloudFormation [12]. AWS's own example shows a short CDK class producing a CloudFormation template of more than 500 lines [12].

So the real choice isn't "declarative or imperative" so much as "a purpose-built configuration language, or loops and functions from a language your team already knows."

The main tools compared

Tool

Language

Where state lives

Cloud scope

Licensing / governance (as of Nov 2026)

Terraform

HCL configuration files

Local file by default; remote backend or HCP Terraform recommended for teams [3]

Any platform with a provider [2]

Business Source License 1.1 for future releases, announced August 10, 2023 [5]

OpenTofu

HCL (Terraform-compatible)

Same model as Terraform

Works with Terraform providers via its own registry [8]

Linux Foundation project; open-source fork of Terraform [6][7]

AWS CloudFormation

JSON or YAML templates

Managed by AWS as stacks [9]

AWS

AWS service

AWS CDK

TypeScript, JavaScript, Python, Java, C#, Go

Deploys via CloudFormation [12]

AWS

Open source [12]

Pulumi

TypeScript, JavaScript, Python, Go, C#, Java, YAML, HCL [13]

Pulumi Cloud by default, or S3, Azure Blob, GCS, local and others [14]

Any platform with a provider

Vendor product; check current license terms

The Terraform and OpenTofu split

On August 10, 2023, HashiCorp announced it was moving future releases of its products, including Terraform, from the Mozilla Public License 2.0 to the Business Source License 1.1, while keeping its APIs, SDKs and almost all other libraries under MPL 2.0 [5]. In response, a group of companies forked the MPL-licensed Terraform code. The Linux Foundation announced OpenTofu, previously named OpenTF, as an open-source successor to the MPL-licensed Terraform on September 20, 2023 [6], and OpenTofu 1.6, its first stable release, reached general availability on January 10, 2024 [7].

OpenTofu's FAQ says it works with state files created by Terraform up to version 1.5.x, uses existing Terraform providers through its own registry, and states an aim of feature parity with future Terraform releases, while leaving the community to decide which features OpenTofu gets [8]. For most teams, the practical question is licensing and roadmap, not syntax. Read the licenses with your legal team rather than relying on summaries.

Drift: when reality stops matching the code

Drift happens when someone changes a resource outside the IaC tool, for example by editing a server's settings in a console during an incident. AWS defines a resource as drifted "if any of its actual property values differ from the expected property values," including if it has been deleted [11]. CloudFormation can run drift detection on a whole stack or individual resources, with documented blind spots: it only checks properties you set explicitly, and some values, like passwords, are never returned by the underlying service [11].

Terraform detects drift as a side effect of planning, because the default plan refreshes its view of real infrastructure first. Its documentation warns that habitually skipping parts of the configuration with -target can lead to "undetected configuration drift" [4].

The cultural rule that follows: once a resource is under IaC, changes go through the code. Emergency console edits should be copied back into the configuration quickly, or the next apply may quietly undo them.

Real-world uses

  • Repeatable environments. Describe an environment once and stamp out identical copies, including in other regions. AWS gives exactly this example for CloudFormation templates [9].
  • Reviewable change control. Because templates are text, you can see "exactly what changes were made, who made them, and when," and revert to a previous version [9].
  • Platform foundations. IaC commonly provisions the clusters and networks that container platforms run on. See our Kubernetes architecture explainer for what those clusters contain, and our cloud computing guide for the service models IaC automates.
  • Security baselines. Identity policies, firewall rules and encryption settings can be defined, reviewed and tested before deployment, which supports the policy-driven model described in our Zero Trust architecture guide.

Benefits

  • Consistency: the same code produces the same infrastructure, reducing snowflake servers.
  • Speed: new environments take minutes of tool time instead of days of tickets.
  • Auditability: version history doubles as a change log.
  • Safer changes: plans and change sets show the blast radius before anything happens [4][10].
  • Disaster recovery: if an environment is lost, the definition of it isn't.

Limitations and risks

  • State is sensitive. Terraform warns that mishandled state can expose "secrets stored in the state file," and advises against storing it in version control or anywhere without locking and access control [3]. Treat state storage as a production secret store.
  • A plan is not a guarantee. AWS notes that change sets don't guarantee a successful update; runtime conditions can still cause failures [10].
  • Drift and break-glass edits. Manual changes undermine the model unless teams detect and reconcile drift [11].
  • Mistakes scale too. The same automation that builds 50 resources correctly can delete 50 resources incorrectly. Review plans that include deletions or replacements with particular care.
  • Learning curve and lock-in. HCL, CloudFormation templates and provider quirks all take time to learn. AWS-native tools only manage AWS, and licensing changes can shift the ground under a tool choice, as the 2023 Terraform change showed [5].

How to choose an IaC tool

  1. Single cloud or several? If you're all-in on AWS and want a managed service, CloudFormation or the CDK keep everything inside AWS [9][12]. If you span clouds or SaaS platforms, a provider-based tool such as Terraform, OpenTofu or Pulumi fits better [2][13].
  2. Configuration language or programming language? Teams of operators often prefer HCL's constrained syntax. Teams of application developers may be more productive with Pulumi or the CDK in a language they already test and lint [12][13].
  3. Licensing posture. If an open-source license is a hard requirement, compare Terraform's BSL terms with OpenTofu's governance before committing [5][7].
  4. State and collaboration. Decide where state lives, who can read it and how locking works before the second engineer joins [3][14].
  5. Pipeline fit. Whatever you pick, run plans automatically on pull requests and require human approval for applies to production.

Outlook

The major IaC tools have converged on the same core loop: declare, preview, apply. Two developments are worth watching. First, the Terraform and OpenTofu communities are diverging on features, so compatibility assumptions should be re-checked at each major release [8]. Second, AI coding assistants are increasingly generating infrastructure code, a trend we covered in our report on AI-written code at large tech firms. That makes the plan-and-review step more important, not less: generated configuration still needs a human reading the diff before it reaches production.

Frequently asked questions

Is infrastructure as code the same as configuration management?

They overlap but focus on different layers. IaC tools like Terraform and CloudFormation mainly provision resources such as networks, VMs and databases. Configuration management tools traditionally configure software inside servers after they exist. Many teams use both.

What is the difference between Terraform and CloudFormation?

CloudFormation is an AWS service that manages AWS resources as stacks defined in JSON or YAML templates [9]. Terraform is a separate tool that uses providers to manage resources on many platforms, and it keeps its own state file [2][3]. Choose CloudFormation for AWS-only, AWS-managed workflows and Terraform (or OpenTofu) for multi-platform estates.

Is Terraform still open source?

Not under its original license. HashiCorp moved its products to the Business Source License 1.1 for releases after its August 10, 2023 announcement [5]. OpenTofu is the Linux Foundation-hosted open-source fork [6][7].

Can I use Python for infrastructure as code?

Yes. Pulumi supports Python alongside TypeScript, Go, C#, Java and others, and the AWS CDK supports Python for AWS resources [12][13]. Under the hood, both still compute a desired state and a diff, so you keep the preview-before-apply safety.

Should I commit Terraform state to Git?

No. HashiCorp advises against storing state in version control because it can contain secrets and lacks locking [3]. Use a remote backend with encryption, locking and tight access control.

What causes configuration drift?

Usually manual changes made outside the IaC tool, such as console edits during an incident or changes by another automation system [11]. Regular plans or drift detection runs surface it so you can either update the code or revert the change.

Sources

  1. Amazon Web Services, "Infrastructure as code," Introduction to DevOps on AWS whitepaper. https://docs.aws.amazon.com/whitepapers/latest/introduction-devops-aws/infrastructure-as-code.html
  2. HashiCorp, "What is Terraform?" https://developer.hashicorp.com/terraform/intro
  3. HashiCorp, "State," Terraform language documentation. https://developer.hashicorp.com/terraform/language/state
  4. HashiCorp, "terraform plan command reference." https://developer.hashicorp.com/terraform/cli/commands/plan
  5. HashiCorp, "HashiCorp adopts Business Source License," August 10, 2023. https://www.hashicorp.com/en/blog/hashicorp-adopts-business-source-license
  6. The Linux Foundation, "Linux Foundation Launches OpenTofu," September 20, 2023. https://www.linuxfoundation.org/press/announcing-opentofu
  7. The Linux Foundation, "OpenTofu Announces General Availability," January 10, 2024. https://www.linuxfoundation.org/press/opentofu-announces-general-availability
  8. OpenTofu, "FAQ." https://opentofu.org/faq/
  9. Amazon Web Services, "What is CloudFormation?" https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html
  10. Amazon Web Services, "Update CloudFormation stacks using change sets." https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-changesets.html
  11. Amazon Web Services, "Detect unmanaged configuration changes to stacks and resources with drift detection." https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-stack-drift.html
  12. Amazon Web Services, "What is the AWS CDK?" https://docs.aws.amazon.com/cdk/v2/guide/home.html
  13. Pulumi, "How Pulumi works." https://www.pulumi.com/docs/iac/concepts/how-pulumi-works/
  14. Pulumi, "State and backends." https://www.pulumi.com/docs/iac/concepts/state-and-backends/