You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?
Terraform & OpenTofu cheat sheet
The commands you learned, in one place.
The loop: init, plan, apply
tofu initGet the suppliers ready for this folder.terraform initThe same job in Terraform.tofu init -upgradePick the newest provider versions your pins allow.tofu planCompare the blueprint with what is built.tofu plan -var tables=6Fill in one variable for this plan.tofu plan -var-file=penang.tfvarsRead variable values from a file.tofu plan -destroyPreview what destroy would delete.tofu plan -out tfplanSave the plan, so apply does exactly this.tofu applyShow the plan, then build it if you type yes.Risk: Carefultofu apply tfplanApply exactly the plan you saved and read.Risk: Carefultofu apply -auto-approveCareful: no question. Only for practice or a pipeline that showed a plan first.Risk: Carefultofu destroyShow what goes, then delete it if you type yes.Risk: Can lose worktofu plan -destroyOnly a preview. Nothing is deleted.Risk: Can lose work
Check and tidy
tofu fmtTidy every .tf file in this folder.tofu fmt -checkOnly check. Lists messy files; changes nothing.tofu fmt -diffShow the changes it makes.tofu validateIs this blueprint drawn right?tofu versionWhich OpenTofu is this?terraform versionThe same question for Terraform.tofu providers lock -platform=linux_amd64 -platform=darwin_arm64Checksums for Linux runners and Apple laptops.tofu show -json tfplan > plan.jsonSave the plan as JSON for Conftest.tofu show tfplanRead a saved plan, exactly as it will be applied.tofu showRead the whole register in a readable way.
State
tofu state listWhat is in the register?tofu state list module.kioskOnly the things inside one module.tofu state show random_integer.tableWhich table number did we get?tofu state rm local_file.signForget the sign. The next plan wants to build it again.Risk: Carefultofu state mv random_pet.stall random_pet.chefThe stall is now called chef in the register.Risk: Carefultofu import random_string.door KANCILAdopt the door code KANCIL as random_string.door.Risk: Carefultofu plan -refresh-onlyDid anything drift?tofu apply -refresh-onlyAccept the drift into the register only. It asks first.tofu plan -detailed-exitcodeExit code 0 = no changes, 1 = error, 2 = changes. Good for nightly drift checks.tofu force-unlock 94da26d5-0aeb-a021-8eda-d41c2046f8f1Free the lock with this ID. Copy the ID from your own error.Risk: Carefultofu plan -lock-timeout=5mWait up to 5 minutes for a busy lock instead of failing at once.Risk: Careful
Workspaces and outputs
tofu outputEvery output, name = value.tofu output -raw stall_nameJust one value, no quotes. Good for scripts.tofu output -jsonEvery output as JSON, for other programs.tofu workspace new testMake a test register and switch to it.Risk: Carefultofu workspace select -or-create testSwitch to test, making it if it is missing.Risk: Carefultofu workspace delete testDelete a workspace. Destroy its things first.Risk: Careful