OpenTofu
OpenTofu
October 3, 2023

OpenTofu Alpha release

By
Ryan Fee

How do I download OpenTofu?

To download the alpha release, go to the release page of the OpenTofu repo and select the binary that corresponds to the OS you will be using OpenTofu on.

What is included?

First off, a complete renaming of Terraform to OpenTofu had to be done for legal reasons. Along with that, the team also had to ensure there was a suitable OpenTofu registry in place as the existing Terraform registry is only allowed to be used with Terraform.

Other than that, from an end user perspective, it is just a difference in the command line. Instead of calling “terraform”, you will now call “tofu”. All of the existing Terraform commands that were present from 1.5.x and below will continue to work.

What do I need to know about the provider registry?

The original Terraform registry is essentially a metadata server that shows all of the information regarding the providers with the providers actually living in third party sources like Github. The team was able to create our own registry, which will ensure that all existing 2260 providers will continue to work without violation of Hashicorp ToS.

The release of the registry is considered alpha with work underway to make a production ready registry. If you’re interested in contributing to the registry, you can find the repo here.

OpenTofu Commands

Once downloaded, there is not much difference between the Terraform 1.5.x and OpenTofu commands. The basic commands remain the same:

tofu
Usage: tofu [global options] <subcommand> [args]

The available commands for execution are listed below.
The primary workflow commands are given first, followed by
less common or more advanced commands.

Main commands:
  init          Prepare your working directory for other commands
  validate      Check whether the configuration is valid
  plan          Show changes required by the current configuration
  apply         Create or update infrastructure
  destroy       Destroy previously-created infrastructure

All other commands:
  console       Try OpenTofu expressions at an interactive command prompt
  fmt           Reformat your configuration in the standard style
  force-unlock  Release a stuck lock on the current workspace
  get           Install or upgrade remote OpenTofu modules
  graph         Generate a Graphviz graph of the steps in an operation
  import        Associate existing infrastructure with a OpenTofu resource
  login         Obtain and save credentials for a remote host
  logout        Remove locally-stored credentials for a remote host
  metadata      Metadata related commands
  output        Show output values from your root module
  providers     Show the providers required for this configuration
  refresh       Update the state to match remote systems
  show          Show the current state or a saved plan
  state         Advanced state management
  taint         Mark a resource instance as not fully functional
  test          Execute integration tests for OpenTofu modules
  untaint       Remove the 'tainted' state from a resource instance
  version       Show the current OpenTofu version
  workspace     Workspace management

Global options (use these before the subcommand, if any):
  -chdir=DIR    Switch to a different working directory before executing the
                given subcommand.
  -help         Show this help output, or the help for a specified subcommand.
  -version      An alias for the "version" subcommand.
tofu init: initializes the working directory where the configuration files are located. All modules, providers, and plugins are downloaded or upgraded during this time.
tofu plan: executes a “dry run” meaning that the resources are not actually created, instead you can see a preview of what to expect if the apply was to happen.
tofu apply: a run in which the resources defined in your configuration files are actually created.

How do I migrate from Terraform to OpenTofu?

Transitioning from Terraform to OpenTofu couldn't be easier, all you have to do is execute Tofu against your existing Terraform state files. As seen here, I have an existing state file that was created using Terraform 1.5.0 and the null resource provider:

{
  "version": 4,
  "terraform_version": "1.5.0",
  "serial": 1,
  "lineage": "d8914af4-4a72-d67d-b390-8307ed7bdf86",
  "outputs": {},
  "resources": [
    {
      "mode": "managed",
      "type": "null_resource",
      "name": "example",
      "provider": "provider[\"registry.terraform.io/hashicorp/null\"]",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "id": "3925604235592252374",
            "triggers": null
          },
          "sensitive_attributes": []
        }
      ]
    }
  ],
  "check_results": null
}
I added the OpenTofu binary, ran a tofu init
tofu init

Initializing the backend...

Initializing provider plugins...
- Reusing previous version of hashicorp/null from the dependency lock file
- Using previously-installed hashicorp/null v3.2.1

OpenTofu has been successfully initialized!

You may now begin working with OpenTofu. Try running "tofu plan" to see
any changes that are required for your infrastructure. All OpenTofu commands
should now work.

If you ever set or change modules or backend configuration for OpenTofu,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
Ran a tofu plan.
tofu plan
null_resource.example: Refreshing state... [id=3925604235592252374]

No changes. Your infrastructure matches the configuration.

OpenTofu has compared your real infrastructure against your configuration and found no differences, so no changes are needed.
Just for good measure,I ran a tofu apply and we can see the only thing that changed was the version, which now shows 1.6.0, which is the current version of OpenTofu I am testing on
{
  "version": 4,
  "terraform_version": "1.6.0",
  "serial": 1,
  "lineage": "d8914af4-4a72-d67d-b390-8307ed7bdf86",
  "outputs": {},
...

Everything worked as expected and no need to do any major migrations, just update the binary!

Use it in Scalr Today!

To switch to OpenTofu in Scalr, you simply need to update your workspace settings. Go to your pipeline settings and search for version 1.6.0 and save. The next run will update your workspace to use OpenTofu!

How do I report issues or contribute?

With any alpha release, it is expected that improvements will be needed and bugs will be identified. If you are interested in contributing or find an issue, please feel free to open an issue in the public repo here.

Start using the Terraform platform of the future.

A screenshot of the modules page in the Scalr Platform