🎓 A1Learner
🔍
0 of 50 lessons completed

The Terraform Workflow: Init, Plan, Apply

The Terraform workflow is the order of three commands: init, plan and apply. Each command has one job, and they always run in that order.

1. Init

Init sets up the folder. It downloads providers and prepares the working directory.

terraform init

2. Plan

Plan compares the file with what exists. It prints a list of changes, and changes nothing.

terraform plan

3. Apply

Apply asks for confirmation, then carries out the plan. Destroy reverses it when practice is done.

terraform apply

Example

# main.tf
terraform {
  required_providers {
    local = {
      source  = "hashicorp/local"
      version = "2.9.1"
    }
  }
}

resource "local_file" "workflow" {
  filename = "workflow.txt"
  content  = "Init, plan, apply."
}

# Commands, in order:
# terraform init
# terraform plan
# terraform apply
# terraform destroy

Key points

  • Init prepares the working folder and downloads the providers it needs.
  • Plan shows what Terraform will create, change or destroy.
  • Apply carries out the plan and makes the change real.
  • Destroy removes everything the configuration manages.
  • Run plan before apply, so a surprise is caught before it happens.

Init sets the folder up. Plan shows the change before it happens. Apply makes it real. Destroy removes it after practice. The order never changes.

Note

Init runs once per folder, while plan and apply run as often as needed.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Rust Playground

Exercise

Which command shows what Terraform will do before it does it?