Understand Terraform’s working cycle from initialization to destroy. Each stage has an important role in ensuring infrastructure is managed safely and consistently.
What Will You Learn? #
Terraform has a structured, repeatable workflow. Understanding each stage — init, plan, apply, and destroy — along with the concepts of idempotency and drift detection, is the key to managing infrastructure with confidence.
Articles in This Section #
| Article | Main Topic |
|---|---|
| Init | Project initialization, downloading providers and modules |
| Plan | Previewing changes before they’re applied — a critical stage for review |
| Apply | Applying changes to the actual infrastructure |
| Destroy | Removing all resources managed by Terraform |
| Execution Plan | Understanding the plan output details in depth |
| Idempotency | Running apply many times without unwanted changes |
| Drift Detection | Detecting changes made outside Terraform (manual changes) |
Workflow Lifecycle #
flowchart TD
A["<b>terraform init</b><br/>Project initialization"] --> B["<b>terraform plan</b><br/>Preview changes"]
B --> C{"Review<br/>Plan"}
C -->|"Approve"| D["<b>terraform apply</b><br/>Apply changes"]
C -->|"Reject"| E["Edit<br/>Configuration"]
E --> B
D --> F{"Need<br/>Cleanup?"}
F -->|"Yes"| G["<b>terraform destroy</b><br/>Remove all resources"]
F -->|"No"| H["Monitoring &<br/>Drift Detection"]
H --> I{"Drift<br/>Detected?"}
I -->|"Yes"| E
I -->|"No"| H
style A fill:#e1f5fe
style G fill:#ffebee
style H fill:#c8e6c9Stage Comparison #
flowchart LR
subgraph Safe["Safe Operations"]
init["init<br/>Doesn't change infra"]
plan["plan<br/>Read-only, preview only"]
end
subgraph Destructive["Potentially Destructive"]
apply["apply<br/>Creates/changes resources"]
destroy["destroy<br/>Deletes resources"]
end
init --> plan
plan --> apply
apply --> destroy
style Safe fill:#e8f5e9
style Destructive fill:#fff3e0Best Practice: Always Plan Before Apply #
# The correct workflow
terraform init # Once only (or when there are provider/module changes)
terraform plan # ALWAYS run this first
terraform apply # Only after reviewing the plan
terraform destroy # Only when you're sure you want to delete
After understanding the workflow, continue to the Concept section to go deeper into declarative concepts and state management.