iac.htora.dev · security templates

Home/Refreshers/Terraform and OpenTofu: refresher

Terraform and OpenTofu

A tool that creates and changes cloud resources to match .tf files. OpenTofu is its open-source fork, and takes the same files with tofu in place of terraform.

Remember

  1. Three commands do most of the work: init, plan, apply. Plan changes nothing.
  2. The state file is Terraform's memory of what it made. It contains secrets in plain text.
  3. terraform.tfstate never goes in Git. .terraform.lock.hcl always does.
  4. Team state lives in a shared bucket that is encrypted, versioned, and locked.
  5. In a plan: + creates, ~ changes, - destroys, and -/+ replaces.

Commands

Download providersterraform init
Previewterraform plan
Make it soterraform apply
Show outputsterraform output
Move local state to a backendterraform init -migrate-state
Clear a stuck lockterraform force-unlock <lock-id>
Remove everything the folder managesterraform destroy

Watch out

  • "forces replacement" next to a small edit means delete and recreate. Stop and read.
  • destroy removes everything the folder manages, including things you were not thinking about.
  • A provider with no version constraint can change behaviour with no commit.
Check it worked

Read the plan's last line first: how many to add, change, and destroy. Stop if destroy is above zero and you did not expect it.

Read the full pageDownload PDF

Registry 0.23.0. Built 2026-11-17.

Made by Habibullah Tora. Source on GitHub. Code under the MIT licence, writing under CC BY 4.0.