This is a complete, hands-on OpenTofu cheat sheet: install, configure, operate, automate and secure it - with copy-paste commands grouped by task. Bookmark it for day-to-day work, incidents and interviews alike.
OpenTofu is a drop-in, MPL-2.0 licensed fork of Terraform under the Linux Foundation. It speaks the same HCL and provider ecosystem, with community governance and features like state encryption.
Why you reach for it
- Open governance and a permissive license
- Drop-in compatibility with existing Terraform code
- Extra features like native state encryption
Installation
brew install opentofu
tofu version
tofu initConfiguration reference
Identical HCL to Terraform - just run with tofu.
terraform {
required_providers { aws = { source = "hashicorp/aws" } }
encryption { # OpenTofu native state encryption
key_provider "pbkdf2" "k" { passphrase = var.state_pass }
method "aes_gcm" "m" { keys = key_provider.pbkdf2.k }
state { method = method.aes_gcm.m }
}
}Core commands you use daily
tofu init
tofu plan -out tfplan
tofu apply tfplanCore workflow (tofu)
tofu init
tofu fmt -recursive && tofu validate
tofu plan -out tfplan
tofu apply tfplan
tofu destroyState
tofu state list
tofu state show aws_s3_bucket.assets
tofu import aws_s3_bucket.assets acme-assets
tofu output -jsonUse it in CI/CD
Swap the binary; the workflow is the same as Terraform.
- uses: opentofu/setup-opentofu@v1
- run: tofu init -input=false && tofu plan -input=falseBest-practice checklist
- Standardize on one binary per project
- Use native state encryption for sensitive state
- Pin provider versions and commit the lock file
Common pitfalls to avoid
- Mixing tofu and terraform state operations in one project
- Assuming 100% provider parity for the newest Terraform-only features
- Local state - use remote, locked backends
Security quick wins
- Encrypt state at rest (native or backend-side)
- Scan with tfsec/Checkov like any Terraform code
Works well with
- Terraform - Declarative, provider-agnostic infrastructure as code with a planned, reviewable change workflow.
- Pulumi - Infrastructure as code in real languages - TypeScript, Python, Go and C# - with a state backend.
- Ansible - Agentless configuration management and provisioning over plain SSH, described in readable YAML.
A cheat sheet is muscle memory on paper - keep it close until the commands live in your fingers.
Want senior help putting OpenTofu to work - or a team bootcamp on it? CodeWizard runs Israel's largest DevOps community and embeds named senior engineers with a transparent hours log. Book a free consult or explore the Academy.