Terraform Lifecycle Explained

Learn the complete Terraform lifecycle: Init, Plan, Apply, Destroy and discover how to safely and efficiently manage cloud infrastructure using Infrastructure as Code.
Sakib Rahman
Feb 27, 2026
3 min read
8 views

Infrastructure as Code (IaC) has transformed the way we build and manage cloud environments. Instead of clicking through a cloud console, we define infrastructure in code and let automation handle the rest.

One of the most important concepts to understand in Terraform is its lifecycle:

Write → Init → Plan → Apply → Destroy

In this blog, we’ll break down each stage clearly with examples so you can confidently use Terraform in real-world projects.

What is Terraform?

Terraform is an Infrastructure as Code (IaC) tool created by HashiCorp. It allows you to define, provision, and manage infrastructure using declarative configuration files written in HCL (HashiCorp Configuration Language).

Terraform works with cloud providers like:

  • Amazon Web Services
  • Microsoft Azure
  • Google Cloud Platform

Now let’s understand how the lifecycle works.

Step 1: Write (Define Infrastructure)

Everything starts with writing configuration files.

Terraform configurations are written in .tf files using HCL.

Example:

plain text
1provider "aws" {
2  region = "us-east-1"
3}
4
5resource "aws_instance" "web" {
6  ami           = "ami-123456"
7  instance_type = "t2.micro"
8}

Here, we are declaring:

  • A provider (AWS)
  • A resource (EC2 instance)

This defines the desired state of infrastructure.

Important:

You are not writing steps. You are describing the final state.

Step 2: Init (terraform init)

Before Terraform can create anything, it must initialize the working directory.

Run:

plain text
terraform init

What happens during init?

  • Downloads required provider plugins
  • Initializes backend (state configuration)
  • Prepares modules
  • Sets up the working directory

Think of init as: “Prepare Terraform to work with this project.”

You only need to run this once per project (or after adding new providers/modules).

Step 3: Plan (terraform plan)

Now comes the most important safety step.

Run:

plain text
terraform plan

Terraform compares:

  • Desired state (your .tf files)
  • Current state (terraform.tfstate or real infrastructure)

It then generates an execution plan showing what will change.

Plan Output Symbols

Example output:

plain text
+ aws_instance.web

Meaning: Terraform will create a new EC2 instance.

Important:

  • plan does NOT change anything.
  • It is a preview step.
  • Always review the plan before applying.

Step 4: Apply (terraform apply)

Once you are satisfied with the plan, run:

plain text
terraform apply

Terraform will:

  • Create resources
  • Modify resources
  • Delete resources
  • Handle dependencies automatically
  • Update the state file

After confirmation, Terraform calls the provider APIs and provisions infrastructure.

At this stage:

  • Infrastructure is live
  • State file is updated
  • Desired state = Actual state

Step 5: State Management

Terraform keeps track of infrastructure using a state file:

plain text
terraform.tfstate

The state file:

  • Maps configuration to real-world resources
  • Stores resource IDs
  • Tracks dependencies
  • Enables drift detection
  • Ensures idempotency

Without state, Terraform wouldn’t know what it created.

In team environments, state is usually stored remotely (e.g., Terraform Cloud or S3 backend) to prevent conflicts.

Step 6: Destroy (terraform destroy)

When you no longer need the infrastructure, run:

plain text
terraform destroy

Terraform will:

  • Generate a destroy plan
  • Delete all managed resources
  • Clean up infrastructure

Common use cases:

  • Cleaning up test environments
  • Cost control
  • Temporary demo environments

Warning:

Always double-check before running destroy in production.

#

Cloud Computing
Terraform