A manually configured AWS virtual private cloud (VPC) can take hours to recreate. Infrastructure as code replaces that work with a reusable description of the desired resources. OpenTofu provides the open-source `tofu` CLI for running Terraform-compatible configurations. section 1.0 section 1.6.6
OpenTofu was forked after Terraform releases starting with version 1.6 moved away from an open-source license. It has remained compatible with Terraform code, so switching runners usually requires little change. Compatibility is not a permanent guarantee: OpenTofu-only language features can make a return to Terraform harder, while new Terraform features may reach OpenTofu later. section 1.6 section 1.6.5
The familiar deployment workflow carries over to `tofu`:
- Run `tofu init` to download needed providers or modules. section 1.6.6 section 1.7
- Run `tofu plan` to compare the workspace’s resources with the desired configuration. section 1.6.6 section 1.7
- Run `tofu apply` to perform the planned actions. section 1.6.6 section 1.7
Listing 7.8 Switching between OpenTofu and Terraform
TF_ENGINE:=terraform #1
ifeq ($(TF_ENGINE), terraform) #2
TF_BINARY:=terraform #3
else ifeq ($(TF_ENGINE), opentofu) #4
TF_BINARY:=tofu #5
endif
.PHONY: format
format:
$(TF_BINARY) fmt #6
This Makefile listing maps a selectable engine name to either `terraform` or `tofu`, then uses the chosen binary for formatting. section 7.2.4
Check formatting with OpenTofu
With that Makefile, run `make format TF_ENGINE=opentofu`. The same target can retain Terraform as its default, making it practical to test both runners without rewriting the target. section 7.2.4
Runner choice also has operational consequences. New releases can introduce breaking changes, so teams supporting multiple versions can use `tenv` to select Terraform and OpenTofu versions. For continuous delivery, check platform support and licensing: the choice of runner can affect which delivery systems are available. section 7.2.5 section 8.6.2
