linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
Intro
Lessons
Footer
linuxlab-TutorialsPricingAboutPrivacy & cookies
Copyright © 2026 LinuxLab. All rights reserved.
linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
  • Introduction
  • Lessons
  • How it works
  • Knowledge base
  • Cheat sheet
  • Capstone
  • Interview prep
home/terraform/how/tf-lifecycle

how/workflow

The core Terraform cycle: init → plan → apply → destroy

What Terraform does on each command. The three sources of truth (HCL, state, the cloud), how they line up and drift apart, and why apply without plan is a bad habit.

Terraform is a machine that keeps three copies of one idea in agreement:

  • HCL files are what you want. The desired state.
  • The state file (terraform.tfstate) is what Terraform thinks about reality. Its own cache.
  • The cloud is what actually exists. The real resources at the provider (or in LocalStack).

The lifecycle is four commands, each working with its own set of these three sources. In the first tutorial lesson you run them in order against a single S3 bucket in LocalStack (see tf-init, tf-plan, tf-apply, tf-destroy). Press ▶ to see what happens behind each command.

step 1/6·00 · nothing has run yet
MAIN.TFжелаемое состояниеTERRAFORM.TFSTATEчто terraform знаетLOCALSTACK / AWSреальностьresource "aws_s3_bucket" "demo" { bucket = "linuxlab-…" tags = { Owner = "student" }}resource "random_id" "suffix" { byte_length = 4}{"version": 4,"serial": 0,"lineage": "8f2a-…","resources": [(пусто)]}RESOURCES(пусто)ничего ещё не запускали

§ steps

  1. A project folder with one file, main.tf. It describes two resources: an S3 bucket and a random suffix for its name.

    State is empty. The cloud is empty. Terraform has not seen either one yet. The commands below run in order.

recap

What to remember:

  • init runs once per project (and after changing the provider or backend). It downloads plugins and creates .terraform.lock.hcl.
  • plan changes nothing. Run it as often as you like. Between refresh and diff everything happens in your head and in RAM, not in the cloud.
  • apply is the only command that actually creates anything. It is also the only one that touches state.
  • After apply, a repeat plan must show No changes. If it shows changes, that is [[drift|drift]], and you go investigate.
  • destroy is symmetric to apply: the state empties, the cloud empties. A mirror.

Next: tf-state-anatomy on what lives inside state, and tf-drift on how HCL and the cloud drift apart.

§ dig into the knowledge base

  • tf-initterraform init: what it does and why it is required
  • tf-planterraform plan: refresh, diff, exit codes
  • tf-applyterraform apply: what it changes, and in what order
  • tf-destroyterraform destroy: the mirror of apply
  • tf-stateWhat is inside the state file

§ try it hands-on

  • ›tf-beginner-01-hello-s3- Hello, S3: your first resource in Terraform
  • ›tf-beginner-04-state- State: what it is and why
  • ›tf-beginner-06-destroy- Destroy: how to tear down cleanly
Footer
linuxlab-
Copyright © 2026 LinuxLab. All rights reserved.
Tutorials
Pricing
About
Privacy & cookies