$ terraform plan -out=tfplan && terraform apply tfplan

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).

$ terraform plan
Plan and apply: code, state and the real cloud
CODE · main.tf aws_s3_bucket.raw aws_db_instance.dwhclass = small STATE · terraform.tfstate aws_s3_bucket.raw aws_db_instance.dwhclass = small REAL CLOUD · AWS API aws_s3_bucket.raw aws_db_instance.dwhclass = small aws_s3_bucket.curatedclass = medium Plan: 1 to add, 1 to change, 0 to destroy. aws_s3_bucket.curatedclass = medium aws_s3_bucket.curatedclass = medium class = large (console edit)Drift: next plan shows ~ dwh class large → medium
NO.STEPCOMMANDTYPEINFO
102planREFRESHread raw, dwh from AWS: match state
202plan+ CREATEaws_s3_bucket.curated
302plan~ UPDATEaws_db_instance.dwh: class small → medium
403applyLOCKstate lock acquired
503applyAPICreateBucket curated · ModifyDBInstance dwh
604applySTATEstate written (serial 42 → 43), lock released
705consoleDRIFTsomeone resized dwh to large by hand
  1. Code, state and cloud agree: a raw bucket and a small dwh database.
  2. You edit main.tf: add a curated bucket and resize the database to medium. Nothing changes in the cloud yet.
  3. 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.
  4. terraform apply takes a lock on the state and calls the cloud APIs. The bucket is created and the database resized.
  5. Terraform writes the new IDs and attributes into the state and releases the lock. All three views agree again.
  6. 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.tfstate on 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 -/+ and destroy in every plan; use moved {} blocks and prevent_destroy on stateful resources.
  • Hard-coding per environment. Copy-pasted prod/ and dev/ 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

Books

  • Terraform: Up and Running, 3rd ed., Yevgeniy Brikman (O’Reilly)
  • Terraform in Action, Scott Winkler (Manning)

Courses