Once we understand Terraform’s core concepts, the next step is learning its core commands — the ones we’ll use daily to build, manage, and clean up cloud infrastructure.
These commands are simple yet powerful. Let’s go step-by-step through each one with clear explanations. We may use AWS cloud examples here but the concepts are the same across any cloud. We will also have hands-on notes for each cloud later.
🧱 1. terraform init — Initialize Our Project
This command prepares your working directory for use with Terraform.
It downloads the required provider plugins (like AWS), sets up the backend if you’re using remote state, and gets your project ready to run.
Example
terraform init
If your configuration contains:
provider "aws" {
region = "us-east-1"
}
Terraform will download the AWS plugin and show:
Terraform has been successfully initialized!
✅ Tip: Always run this when starting a new project or after cloning a repository.
🧩 2. terraform validate — Check for Errors
This command verifies that your Terraform configuration files are syntactically valid and internally consistent.
It doesn’t connect to AWS — it just ensures your .tf files are correct.
Example
terraform validate
If everything is good:
Success! The configuration is valid.
If there’s an issue, Terraform will highlight the line and reason for the error.
✅ Tip: Run this before applying changes to catch typos and syntax mistakes early.
🧭 3. terraform plan — Preview Changes
The plan command creates an execution plan showing what Terraform will do — what resources will be created, changed, or destroyed.
It’s like a dry run that helps you confirm changes before applying them.
Example
terraform plan
Output:
+ aws_instance.web_server will be created
+ aws_s3_bucket.logs will be created
The + symbol means Terraform will add these resources.
✅ Tip: Always review the plan carefully before applying to avoid unexpected changes.
🚀 4. terraform apply — Deploy Infrastructure
This command executes the plan and actually creates or updates your AWS infrastructure.
Example
terraform apply
Terraform will show you the plan again and ask for confirmation:
Do you want to perform these actions?
Only 'yes' will be accepted to approve.
Enter a value: yes
Once confirmed, Terraform connects to AWS and provisions your resources.
✅ Tip: For automation, you can use:
terraform apply -auto-approve
to skip manual confirmation.
🔍 5. terraform show — View Current State
After applying, you can use terraform show to display details about the infrastructure Terraform manages — pulled from your state file (terraform.tfstate).
Example
terraform show
Output:
# aws_instance.web_server:
resource "aws_instance" "web_server" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
}
✅ Tip: This command helps verify what’s actually deployed and tracked by Terraform.
🧹 6. terraform destroy — Clean Up
When you’re done, terraform destroy removes all resources created by Terraform.
It’s the safe and efficient way to tear down your infrastructure.
Example
terraform destroy
Terraform will confirm before deletion:
Do you really want to destroy all resources?
Only 'yes' will be accepted to confirm.
Once confirmed, Terraform deletes the AWS resources and updates the state file.
✅ Tip: Never manually delete Terraform-managed resources from the AWS Console — it can break your state file.
🧰 7. Other Helpful Commands
| Command | Description |
|---|---|
terraform fmt | Formats .tf files to make them neat and consistent. |
terraform output | Displays outputs (like IP addresses or resource names). |
terraform version | Shows the installed Terraform version. |
terraform workspace | Lets you manage multiple environments (dev, test, prod). |
🪜 Typical Terraform Workflow
Here’s a quick reference workflow you can follow in any project:
terraform init # Initialize project and providers
terraform validate # Check syntax and structure
terraform plan # Preview what will happen
terraform apply # Deploy resources to AWS
terraform show # View current state
terraform destroy # Clean up resources
✅ Tip: Store your Terraform files in version control (like GitHub) — it’s the best way to track and collaborate on infrastructure changes.
🧠 Summary
Terraform’s core commands form a simple, repeatable process for managing cloud resources.
Once you get used to this workflow, you’ll be able to build and destroy environments confidently — all with code.
Quick Recap
| Step | Command | Purpose |
|---|---|---|
| 1 | terraform init | Initialize your project |
| 2 | terraform validate | Check for syntax issues |
| 3 | terraform plan | Preview changes |
| 4 | terraform apply | Create or update resources |
| 5 | terraform show | Display the current state |
| 6 | terraform destroy | Remove all resources |
💬 “Master these few commands, and you can manage entire cloud environments from your terminal.”