Terraform Workflow
In the kingdom of cloud infrastructure, Terraform acts like a master architect. But every architect follows a lifecycle that ensures the blueprint becomes reality. Think of Terraform as a city planner for the cloud. The workflow is the journey from drawing the map to building the city, and sometimes tearing it down. Here’s how it works:
This Workflow Matters
- Write: You design infrastructure like software.
- Plan: You preview changes safely.
- Apply: You build automatically.
- Destroy: You clean up when done.
Write: Draw the Blueprint
You start by writing configuration files (.tf) in HCL (HashiCorp Configuration Language).
resource "aws_instance" "web" {
ami = "ami-123456"
instance_type = "t2.micro"
}
This says: “I want a small web server on AWS using this image.”
Think of this as writing a recipe. You’re listing ingredients (AMI, instance type) but haven’t cooked yet.
Plan: Preview the Construction
terraform plan
Terraform checks your blueprint against the current state (terraform.tfstate) and tells you what will happen.
+ aws_instance.web will be created
This is like a shopping list before cooking. It shows what Terraform will add, change, or remove - without actually doing it yet.
Apply: Build the City
terraform apply
Terraform provisions the resources.
Example: It spins up the EC2 instance on AWS, connects it to the network, and makes it ready.
This is like cooking the recipe. You follow the plan, and the dish (server) is ready to serve.
Destroy: Controlled Demolition
terraform destroy
Terraform removes everything defined in your .tf files.
Example: The EC2 instance is deleted, the network is torn down, and costs stop.
This is like cleaning up after dinner - putting away dishes and clearing the table so nothing is left behind.
The Hackers Notebook
Imagine you’re building a simple website:
- Write: You define one server and one database in Terraform files.
- Plan: Terraform shows it will create 2 resources.
- Apply: Terraform builds the server and database in AWS.
- Destroy: When the project ends, you run destroy, and both resources vanish - no leftover costs.
Terraform’s workflow is a disciplined journey: from imagination to prediction, from creation to destruction. It ensures infrastructure is not just built, but built predictably, safely, and collaboratively - like a city that can rise, evolve, and vanish at will.
