OpenTofu
OpenTofu is an open-source fork of Terraform that was created in response to HashiCorp's license change from MPL 2.0 to BSL 1.1. It maintains full compatibility with Terraform while being developed under the Mozilla Public License 2.0.
What is OpenTofu?
OpenTofu is a community-driven Infrastructure as Code (IaC) tool that provides the same functionality as Terraform but with a more permissive open-source license. It's maintained by the OpenTofu Foundation and the broader community.
Key Features
- Terraform Compatibility: 100% compatible with existing Terraform configurations
- Open Source: Licensed under MPL 2.0 (Mozilla Public License)
- Community Driven: Developed by the community for the community
- Enhanced Features: Additional features and improvements over original Terraform
- No Vendor Lock-in: Free from commercial licensing restrictions
OpenTofu vs Terraform
Feature | OpenTofu | Terraform |
---|---|---|
License | MPL 2.0 (Open Source) | BSL 1.1 (Business Source) |
Cost | Free | Free for individuals, paid for enterprises |
Community | Open community governance | HashiCorp controlled |
Compatibility | Terraform compatible | Original |
Future Development | Community driven | HashiCorp driven |
Installation
Using Package Managers
Homebrew (macOS):
brew install opentofu
APT (Ubuntu/Debian):
wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install opentofu
YUM/DNF (RHEL/CentOS/Fedora):
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
sudo yum -y install opentofu
Basic Usage
OpenTofu uses the same commands as Terraform:
# Initialize
tofu init
# Plan
tofu plan
# Apply
tofu apply
# Destroy
tofu destroy
Migration from Terraform
Migrating from Terraform to OpenTofu is straightforward:
- Install OpenTofu alongside Terraform
- Replace terraform commands with tofu commands
- Update CI/CD pipelines to use
tofu
instead ofterraform
- No configuration changes needed - all
.tf
files work as-is
Enhanced Features
1. Improved State Management
- Better state file handling
- Enhanced state locking mechanisms
- Improved state migration tools
2. Enhanced Provider Support
- Better provider version management
- Improved provider caching
- Enhanced provider development tools
3. Better Error Handling
- More descriptive error messages
- Improved debugging capabilities
- Better validation feedback
Best Practices
- Use version control for all OpenTofu files
- Store state remotely with proper locking
- Use modules for reusable components
- Implement proper variable validation
- Use workspaces for environment separation
- Keep provider versions pinned
When to Use OpenTofu
Choose OpenTofu when:
- You want to avoid vendor lock-in
- You need true open-source licensing
- You want community-driven development
- You're starting new projects
- You want enhanced features over Terraform
Stick with Terraform when:
- You have existing enterprise support contracts
- You need HashiCorp's commercial features
- Your organization requires vendor support
- You're heavily invested in Terraform Cloud
Community and Support
- GitHub: github.com/opentofu/opentofu
- Documentation: opentofu.org
- Discord: Community Discord server
- Forums: Community forums for support