The Six Commands: Terraform Core Workflow
Terraform manages infrastructure as code through a small, disciplined set of commands. Each one has a single job — formatting, validating, planning, or applying — and together they form the loop every Terraform project runs on, from a first init to a final destroy.
Read Before You Write
Terraform never touches your infrastructure blindly. Every change passes through a preview stage first — that's the core discipline the workflow enforces: describe, then preview, then apply, never skip straight to the last step.
init · fmt · validate · plan
These four commands read your configuration and, at most, your provider APIs. None of them create, modify, or delete a single real resource.
apply · destroy
Only these two commands change actual infrastructure — and both stop to ask for typed confirmation before doing so, unless you pass -auto-approve.
The Six Commands
01 / SETUP
terraform init
Initializes a project: downloads provider plugins, pulls in modules, creates the .terraform/ directory, and configures the backend.
- run when First use, after changing providers/backend, or after cloning a repo.
Initializing provider plugins...
- Finding hashicorp/aws...
Terraform has been successfully initialized!02 / PREVIEW
terraform plan
Compares current infrastructure against your configuration and shows exactly what would be created, modified, or destroyed. Nothing is changed.
- mental model "Here's what I'm going to do. Is it okay?"
+ aws_instance.web
Plan: 1 to add, 0 to change, 0 to destroy.terraform apply
Reads the configuration, generates a plan, asks for confirmation, then executes the changes for real.
- CI/CD Skip the prompt with
terraform apply -auto-approve.
Do you want to perform these actions?
Enter a value: yesterraform destroy
Deletes every resource Terraform manages for this configuration. Asks for confirmation the same way apply does.
- caution Use carefully, especially in production.
-auto-approveskips the prompt.
Destroy complete!
Resources: 5 destroyed.05 / STYLE
terraform fmt
Automatically rewrites your .tf files to Terraform's standard style — consistent spacing, aligned = signs, cleaner reviews.
resource "aws_instance" "web" {
ami = "ami-123"
instance_type = "t2.micro"
}06 / CHECK
terraform validate
Checks that your configuration is syntactically valid — required arguments, block structure, and references. It never contacts your cloud provider.
- tip Run this before
planto catch mistakes early.
Success! The configuration is valid.
Error: Missing required argumentThe Typical Workflow
- Write Terraform code
- ↓
- terraform fmt
- ↓
- terraform validate
- ↓
- terraform init
- ↓
- terraform plan
- ↓
- terraform apply
- ↓
- Infrastructure Created
- ↓
- terraform destroy (when no longer needed)
terminalEND TO END
$ terraform fmt && terraform validate
$ terraform init
$ terraform plan
$ terraform applyQuick Summary
| Command | Purpose | Changes Infrastructure? |
|---|---|---|
terraform init | Initialize project, download providers/modules | No |
terraform fmt | Format Terraform code | No |
terraform validate | Validate configuration syntax | No |
terraform plan | Preview proposed changes | No |
terraform apply | Create or update infrastructure | Yes |
terraform destroy | Delete managed infrastructure | Yes |