The Terraform lifecycle is a predictable process that ensures your desired state (HCL code) matches the actual state (Cloud resources).
1. Write: Define the Desired State
You describe what you want in your .tf files.
main.tf:
resource "aws_s3_bucket" "my_bucket" {
bucket = "my-unique-devops-bucket-2026"
}2. Init: Initialize the Workspace
This step prepares your environment and ensures all plugins are ready.
Action:
terraform init3. Plan: Preview the Changes
Terraform compares your code with what is already in the cloud and tells you the difference.
Action:
terraform planResult:
# aws_s3_bucket.my_bucket will be created
+ resource "aws_s3_bucket" "my_bucket" {
+ arn = (known after apply)
+ bucket = "my-unique-devops-bucket-2026"
+ force_destroy = false
+ id = (known after apply)
...
}
Plan: 1 to add, 0 to change, 0 to destroy.4. Apply: Reach the Desired State
Terraform executes the plan and updates the State File (terraform.tfstate).
Action:
terraform apply -auto-approve5. Summary: Why this workflow matters?
- Safety: The
planstep prevents accidental destructions. - State Management: The state file keeps track of everything, so you don't have to.
- Collaboration: Everyone on the team follows the same steps, making infrastructure changes predictable.