
What Is Infrastructure as Code (IaC)?
July 9, 2026 · 10 min read
Infrastructure as Code (IaC) is the approach of defining and managing your infrastructure (servers, networks, databases) with version-controlled code files instead of clicking around a cloud console. Whatever the code says, the infrastructure is.
The problem with manual setup
- Not reproducible: you can't rebuild the same environment identically twice
- Undocumented: no record of who changed what and why
- Error-prone: manual clicking = human error
- Doesn't scale: managing 50 servers by hand is impossible
What IaC solves
Because your infrastructure is now code: it's versioned in Git (who changed what, when), goes through code review, can be rebuilt from scratch with one command, and keeps dev/test/prod identical.
First step with Terraform
Terraform is the most common IaC tool and works with many providers (AWS, GCP, Azure...). You write the desired state declaratively; Terraform computes the diff against reality and applies it:
resource "aws_s3_bucket" "data" {
bucket = "cloudpuz-example-bucket"
}
# terraform init → initialize
# terraform plan → see what will happen
# terraform apply → applyCase: adopt a hand-created resource into IaC
In real life most teams inherit hand-built infrastructure and bring it under IaC later. Let's put an S3 bucket created via the console under Terraform management — without deleting and recreating it.
- 1Declare the resource in code (don't apply yet)
- 2Bind the existing resource to state with terraform import
- 3terraform plan → align code to reality until you see 'No changes'
- 4Now it's IaC-managed: changes go through code review + plan
$ terraform import aws_s3_bucket.data cloudpuz-existing-bucketImport successful!$ terraform plan~ aws_s3_bucket.data tags: {} -> {Env="prod"} # code and reality differ# Align code to reality (add the tags), then:$ terraform planNo changes. Your infrastructure matches the configuration. # ✓ now IaC-managed
Warning
Common mistake: running apply without importing. Since Terraform doesn't see the resource in its state, it tries to create a SECOND one with the same name and conflicts (e.g. 'BucketAlreadyExists'). Import first, then plan.
Mini task
Create an S3 bucket (or a local_file) by hand in the console. Declare it in Terraform, adopt it with 'terraform import', and align the code until 'plan' says 'No changes'. Bonus: change a tag in the console and see the drift in plan.
Hands-on task — try it in your browser
IaC is central to modern DevOps. To practice Terraform state, modules, and real providers, check out Cloudpuz's Terraform labs.
Official sources
Last verified: 2026-07-17
Frequently Asked Questions
What is Infrastructure as Code (IaC)?
Infrastructure as Code (IaC) is the approach of defining and managing your infrastructure (servers, networks, databases) with version-controlled code files instead of clicking around a cloud console. Whatever the code says, the infrastructure is. This makes infrastructure versionable, reviewable, and reproducible.
What are the problems with setting up infrastructure by hand?
Manual setup is not reproducible; you can't rebuild the same environment identically twice. It's also undocumented (no record of who changed what and why), error-prone due to human clicking, and doesn't scale — managing 50 servers by hand is practically impossible.
What problems does IaC solve?
Because infrastructure is now code, it's versioned in Git and it's clear who changed what and when. It goes through code review, can be rebuilt from scratch with one command, and keeps dev/test/prod environments identical.
How do you get started with IaC using Terraform?
Terraform is the most common IaC tool and works with many providers such as AWS, GCP, and Azure. You write the desired state declaratively; Terraform computes the diff against reality and applies it. The core flow is: `terraform init` initializes, `terraform plan` shows what will happen, and `terraform apply` applies it.
How do you bring a hand-created resource under Terraform management?
First declare the resource in code (don't apply yet), then bind the existing resource to state with `terraform import`. Then align the code to reality with `terraform plan` until you see 'No changes'. Running apply without importing makes Terraform try to create a second resource with the same name and conflict (e.g. 'BucketAlreadyExists').
Reading isn't enough — do it.
Practice these topics in an interactive terminal in your browser.