Migrating from Terraform to OpenTofu

OpenTofu is already on it’s stable release version 1.6, totally compatible with Terraform, new features which currently doesn’t exist on Terraform are going to start to pop up in OpenTofu from 1.7 onward, I expect.

Let’s do not waste much time and go straight to the point by giving you a simple but 100% people’s use case demo.

For this demonstration I will deploy a storage account in Microsoft Azure using Terraform and take over the deployment with OpenTofu.

Inside my working directory you can see that I have only 1 .tf file for my storage account deployment, typical Terraform HCL deployment, nothing special.

Let’s run the terraform init command:

Let’s run terraform plan command:

As you can see I have 2 resources to be created, 0 changes and 0 to be destroyed, so let’s now run terraform apply:

As result, 2 resources have been deployed in Microsoft Azure , 1 resource group and 1 storage account.

In the image below you can see that we have all files and directories expected from a Terraform deployment, the .terraform and the tfstate file among with the lock.hcl and the .backup.

Let’s start taking it over with OpenTofu by downloading the binary.

Here you will find the link to download the binaries accordingly your OS.

https://opentofu.org/docs/intro/install

Let’s quickly install it on Linux, here I am using Ubuntu 22.04.

It’s also available on https://snapcraft.io/ for Ubuntu or simply install it by running:

 snap install --classic opentofu

After installation if you’re in your deployment directory, without make any changes in your code just run tofu init

and then run tofu plan

You can see that tofu automatically reads the tfstate file and understand that there is nothing to deploy, this is because literally nothing has changed and tofu is compatible with terraform, so far with the version that Terraform was before moving to BSL license, Terraform 1.7, and the idea is indeed to continue compatible with Terraform with a plus of adding features that the community used to request in the past and were not implemented.

Now I will make a small change in my demo.tf file and run a tofu plan:

The change is of course not matching with the current state so tofu now take it over and requests the change.

Now you can run the tofu apply to apply your changes.

You can see now that the change has been applied and you can move on with OpenTofu for your deployments.

Conclusion:

I understand this was a small deployment example, however this is not different on what you will perform on higher scale deployments, OpenTofu is compatible with Terraform and it’s stable, working beautifully, you don’t need to be scared, or if you are, which is totally normal, just wait a little bit until more people start to use it and you see how the market will behave.

What are you plans regarding Terraform?