Infrastructure Provisioning
Infrastructure provisioning is creating and changing cloud resources (networks, buckets, databases, clusters, IAM roles) from code. You declare the resources you want; a provisioning tool calls the cloud APIs to make reality match, and remembers what it created so it can update or delete it later.
Terraform is the most widely used tool, and its open-source fork OpenTofu is a drop-in alternative. Both use HCL (HashiCorp Configuration Language) and the same providers: plugins that translate resources into API calls for AWS, GCP, Azure, Kubernetes, Snowflake, Databricks, Confluent and hundreds more.
Three views of the same infrastructure
Terraform compares three things: your code (what you want), the state file (what Terraform created last time, with IDs) and the real cloud (what actually exists).
| NO. | STEP | COMMAND | TYPE | INFO |
|---|---|---|---|---|
| 1 | 02 | plan | REFRESH | read raw, dwh from AWS: match state |
| 2 | 02 | plan | + CREATE | aws_s3_bucket.curated |
| 3 | 02 | plan | ~ UPDATE | aws_db_instance.dwh: class small → medium |
| 4 | 03 | apply | LOCK | state lock acquired |
| 5 | 03 | apply | API | CreateBucket curated · ModifyDBInstance dwh |
| 6 | 04 | apply | STATE | state written (serial 42 → 43), lock released |
| 7 | 05 | console | DRIFT | someone resized dwh to large by hand |
- Code, state and cloud agree: a raw bucket and a small dwh database.
- You edit main.tf: add a curated bucket and resize the database to medium. Nothing changes in the cloud yet.
- terraform plan refreshes from the cloud, diffs it with your code and prints the changes: 1 to add, 1 to change, 0 to destroy. A reviewer reads this in the pull request.
- terraform apply takes a lock on the state and calls the cloud APIs. The bucket is created and the database resized.
- Terraform writes the new IDs and attributes into the state and releases the lock. All three views agree again.
- Someone resizes the database in the console. Reality has drifted from code; the next plan will propose reverting it, so either import the change into code or stop manual edits.
The code behind the figure:
terraform {
backend "s3" { # remote, shared, locked state
bucket = "acme-tf-state"
key = "data-platform/prod.tfstate"
region = "eu-central-1"
use_lockfile = true
}
}
resource "aws_s3_bucket" "raw" { bucket = "acme-lake-raw" }
resource "aws_s3_bucket" "curated" { bucket = "acme-lake-curated" }
resource "aws_db_instance" "dwh" {
identifier = "dwh"
engine = "postgres"
instance_class = "db.m7g.large" # "medium" in the figure
# ...
}The workflow
| Command | What it does |
|---|---|
terraform init |
Download providers and modules, configure the backend |
terraform fmt / validate |
Format and statically check the code |
terraform plan |
Show the diff between code and reality; changes nothing |
terraform apply |
Execute a plan, then update state |
terraform import or import {} blocks |
Bring existing resources under management |
terraform destroy |
Delete everything in this state |
In a team, run plan automatically on every pull request and apply only from CI after merge, with tools such as Atlantis, HCP Terraform, Spacelift or plain CI/CD.
Terraform, OpenTofu and alternatives
In 2023 HashiCorp moved Terraform from the open-source MPL license to the source-available Business Source License, and IBM completed its acquisition of HashiCorp in 2025. The community forked the last open version as OpenTofu, now governed by the Linux Foundation. For most users the two are interchangeable; OpenTofu adds features such as client-side state encryption.
| Tool | Language | State | Best for |
|---|---|---|---|
| Terraform / OpenTofu | HCL | State file in a backend | Multi-cloud, largest provider ecosystem |
| Pulumi | Python, TypeScript, Go, C#, Java | Pulumi Cloud or a backend | Teams that want loops, types and tests in a general-purpose language |
| AWS CloudFormation / CDK | YAML/JSON / TypeScript, Python… | Managed by AWS | AWS-only shops |
| Azure Bicep | Bicep DSL | Managed by Azure | Azure-only shops |
| Crossplane | Kubernetes YAML | Kubernetes etcd | Platforms that manage everything as Kubernetes resources with continuous reconciliation |
Common mistakes
- Local state. A
terraform.tfstateon a laptop gets lost or overwritten. Use a remote backend with locking and versioning from day one. - Not reading the plan. A renamed resource can show up as destroy and create. For a database, that means data loss. Look for
-/+anddestroyin every plan; usemoved {}blocks andprevent_destroyon stateful resources. - Hard-coding per environment. Copy-pasted
prod/anddev/folders drift apart. Use modules with variables, one root per environment. - Unpinned providers. A new major provider version can change behaviour. Pin versions and commit
.terraform.lock.hcl.
Learning Resources
Official
- Terraform tutorials (HashiCorp)
- Terraform language documentation
- OpenTofu documentation
- Pulumi documentation
- Crossplane documentation
Books
- Terraform: Up and Running, 3rd ed., Yevgeniy Brikman (O’Reilly)
- Terraform in Action, Scott Winkler (Manning)