A
Etienne Deneuve
Mar 10, 2024 · 5 min read

OpenTofu - An Open-Source Alternative to Terraform

Side view worker wearing gloves

What is IaC?

Before IaC, IT personnel would have to manually change configurations to manage their infrastructure. With IaC, infrastructure configuration takes the form of a code file, making it easy to edit, copy, and distribute. Notable IaC tools include Terraform, AWS Cloud Formation, Azure Resource Manager and Puppet. The benefits of IaC comprise increased consistency and accuracy, decreased risk, stronger security, elimination of configuration drift, stable and scalable environments, speed and efficiency, and cost savings. IaC tools automate the process of setting up, modifying, and maintaining IT infrastructure, enabling businesses to deliver stable environments rapidly and at scale.

The Emergence of OpenTofu as an Alternative to Terraform

OpenTofu emerged as a viable alternative to Terraform due to the sudden transition of Terraform to a non-open-source license, which was met with significant backlash from the open-source community. This led to the creation of the OpenTF Manifesto, which called for the reversion of the license for Terraform to an MPL widely accepted open-source license. The manifesto gathered over 35K GitHub stars, and on August 25th, 2023, the OpenTF initiative was publicly announced as an open-source fork of Terraform, leading to the birth of OpenTofu.

OpenTofu: Overview & Key Components

OpenTofu is an open-source infrastructure as a code tool that allows users to define both cloud and on-prem resources in human-readable configuration files that can be versioned, reused, and shared. It is a fork of Terraform version 1.5.6 and is written in the Go programming language. OpenTofu uses a declarative approach, meaning that it describes the desired state of the infrastructure, and it is up to the tool to determine how to achieve that state. Here are some of the key components of OpenTofu:

  1. Execution Plan: OpenTofu generates an execution plan that outlines the actions it will undertake and seeks the user’s confirmation before executing any operations, such as the creation, modification, or deletion of infrastructure components.

  2. State Management: OpenTofu keeps track of the state of managed infrastructure, ensuring that changes are applied incrementally and consistently. It also maintains a state file, serving as a source of truth for the environment.

  3. Providers: OpenTofu is compatible with various providers, including cloud service providers like Microsoft Azure, AWS, and Google Cloud Platform (GCP). It accesses them through their APIs ( application programming interfaces).

  4. Declarative Configuration: OpenTofu’s configuration files are declarative, describing the end state of the infrastructure. This approach enables efficient resource provisioning by establishing resource dependencies and concurrently creating or modifying non-dependent resources.

What is different from Terraform?

The differences between OpenTofu and Terraform are primarily related to their licensing, governance, and community-driven development. Here are the key differences:

  • Licensing: OpenTofu is released under the Mozilla Public License (MPL), a permissive open-source license, while Terraform is released under the Business Source License (BSL), which imposes certain restrictions on its commercial usage.

  • Governance: OpenTofu is managed under a Linux foundation, ensuring its open-source nature and neutral governance model. On the other hand, Terraform is governed by HashiCorp.

  • Community-Driven Development: OpenTofu is developed collaboratively with no single company being able to dictate its future. It aims to maintain feature parity with Terraform for future releases and is driven by the community. In contrast, Terraform’s development is directed by HashiCorp.

  • Compatibility and Future Outlook: OpenTofu is a drop-in replacement for Terraform and is compatible with Terraform versions 1.5.x and most of 1.6.x. It is suitable for both personal and production use. OpenTofu’s roadmap includes planned features and community-driven enhancements. On the other hand, Terraform continues to evolve, with HashiCorp announcing new version releases and feature updates.

  • OpenTofu Registry: OpenTofu has its registry, that provides a centralized location for discovering and using providers and modules, making it easier for users to manage infrastructure. This has contributed to OpenTofu’s growing adoption and support within the open-source community.

How to switch from Terraform to OpenTofu?

To switch from Terraform to OpenTofu in an existing project, the following steps need to be applied:

1. Preparation: Apply all changes with Terraform before proceeding to ensure a smooth transition.

2. Installation: It can be installed as a standalone binary, check the doc https://opentofu.org/docs/intro/install/ or it can be installed using Homebrew on macOS:

Terminal window
brew update
brew install opentofu

3. Initialization: Run the following command in the directory where your Terraform code resides. OpenTofu will download any providers and modules referenced in your configuration from the OpenTofu registry.

Terminal window
tofu init

4. Plan Inspection: Inspect the plan generated by OpenTofu to confirm that it aligns with your expectations.

Terminal window
tofu plan

5. Implementation: Apply the changes with OpenTofu.

Terminal window
tofu apply

In conclusion, OpenTofu signifies a substantial evolution in the Infrastructure as Code (IaC) domain. Its dedication to open-source ideologies, community-driven development, and feature equivalence with Terraform places it as a promising instrument for managing IT infrastructure. As the tool continues to mature and advance, it is set to play a vital role in defining the future of Infrastructure as Code.

OpenTofu Infrastructure As Code Terraform

Related articles