Infrastructure as code
Built by clicking
Months ago, Remy set up Shard Garden's servers by clicking through the cloud console. Nobody remembers every setting now, and staging differs from production in ways nobody can list.
Infrastructure as code
Infrastructure as code writes servers, databases and networks down in files. Terraform, a popular tool for it, lets a team "build, change, and version cloud and on-prem resources safely and efficiently."
Its files are declarative: they "describe the end state of your infrastructure", not the clicks to get there. They live in Git and are reviewed in pull requests, like code.
Quick check
What does a declarative Terraform file describe?
- What should exist when it is done
- Every click, in order
- Only what to delete
Show the answer
What should exist when it is done
Declarative means the end state. Terraform works out the steps to get there.
Write, plan, apply
Terraform works in three steps:
- Write"You define resources" in files.
- PlanTerraform "creates an execution plan describing the infrastructure it will create, update, or destroy".
- Apply"On approval", it makes the changes "in the correct order".
Read the plan
1# google_firestore_database2# .saves must be replaced3-/+ resource ... "saves"4Plan: 1 to add,5 0 to change,6 1 to destroy.
What will happen if Remy approves this plan?
- The saves database is destroyed and a new one is created
- One setting changes in place
- Nothing: adding one and destroying one cancel out
Show the answer
The saves database is destroyed and a new one is created
"-/+" and "must be replaced" mean destroy, then create a new one. A new database starts empty, so Remy stops and finds out why before approving.
State: what Terraform remembers
Terraform "keeps track of your real infrastructure in a state file, which acts as a source of truth for your environment."
When someone changes a setting by hand in the console, the real thing drifts away from the files. The next plan shows the difference.
Quick check
Priya changed a database setting by hand in the console. What will the next plan show?
- A change, to put the setting back to what the files say
- Nothing: the console change is now permanent
- An error that stops all plans
Show the answer
A change, to put the setting back to what the files say
The files are the source of truth. To keep Priya's change, it goes into the files and through a review.
Same files, three environments
Shard Garden's dev, staging and production are built from the same files, with one variable for the environment's name and size. Staging really matches production, because the same code made both.
Quick check
Why build staging from the same files as production?
- So staging really matches production
- Files make staging cheaper
- Terraform can only read one set of files
Show the answer
So staging really matches production
Staging is a rehearsal. If it is built differently, it can pass changes that production then rejects.
And the game server itself?
The servers are now code. The game server program still needs to run the same way on every one of them.
Bolt says: Next: containers.
Fact-checked 12 October 2026
- HashiCorp: What is Terraform? developer.hashicorp.com