Podcast about DevSecOps

#64 - From Terraform to OpenTofu: Story From the Trenches

Across 250 to 300 stacks, fixing existing problems took more work than switching the binary.

18 min read

In this episode of DevSecOps Talks, Andrey and Mattias are joined by Timur Bublik, Platform Engineering Lead at TIER Mobility. As always, it’s practitioners for practitioners as they discuss the migration from Terraform to OpenTofu, TACOS tools, and how SpaceLift is used in Timur’s organization. Listen in as they dive into their three favorite features of SpaceLift and how TACOS tools like SpaceLift fit into the classic CI/CD pipeline.

Discuss the episode or ask us anything on LinkedIn


Your Terraform version has a ceiling now

If you run Terraform through a platform you pay for, somebody else decides which version of the binary you get, and in August 2023 that decision was taken out of their hands. HashiCorp moved Terraform to the Business Source License, and the announcement is blunt about what happens to vendors selling a competing service: they “will no longer be able to incorporate future releases, bug fixes, or security patches.” If your runs happen on Spacelift, env0 or Scalr, that sentence is about you, one layer down. Run Terraform in your own pipeline and it isn’t: the same company’s licensing FAQ says the BSL “imposes no restrictions on internal use of our tooling”, and a vendor outside that permission can still ask for commercial terms. The ceiling is specific, and it lands on the platform you bought.

From the inside it feels like nothing for a while. Our stacks sat on 1.5.7, the last release under the old license, and being a couple of months behind costs you nothing in week one. Then 1.6 shipped a test framework, 1.7 added for_each on import blocks and a removed block, and the pile of things you can’t have keeps growing while the odds of the ceiling lifting stay somewhere near zero.

Timur Bublik, engineering lead for the SRE team at TIER Mobility in Berlin, joined us after his team finished moving the company’s infrastructure off Terraform. TIER runs the green e-scooters and e-bikes you’ve seen in European cities, all of it managed as code, across 250 to 300 stacks. This is what that migration actually cost, and what the tooling question looks like once you’ve done it.

Licensing picks your binary before features do

Start with the reason, because the feature comparison is the wrong place to look in early 2024.

Why move to OpenTofu when the two tools do almost the same things?

Because the binary your automation platform is allowed to download is a licensing question, not a technical one, and the answer was decided for you.

OpenTofu 1.6.0 went GA on 10 January 2024 under the Linux Foundation, and at this point there isn’t much in it that Terraform lacks. The one genuinely interesting difference is still unreleased. State encryption arrived in 1.7.0-alpha1, published on 14 March 2024, and the project’s call for testers four days later is clear about what you are picking up: “Do not test this release on a production project! It is not a stable release!”

It matters anyway, because of where state files end up. We manage Vault secrets with Tofu, which turns the state file into a secret store, and that state file lives in an S3 bucket. Buckets get opened to the public by accident often enough that this is a real exposure, not a theoretical one.

The other half of the answer is direction. The OpenTofu maintainers are working through things the community asked about for years, with their own view on what belongs in the tool. They won’t build everything people want, and that view is interesting in its own right.

TACOS, and why staying on Terraform narrows the shelf

Licensing also decides something slower and more expensive: which tool you get to buy next year.

What is a TACOS tool?

TACOS stands for Terraform automation and collaboration software: a platform that runs your Terraform with a workflow around it, instead of you wiring terraform plan into a generic pipeline.

The category matters because of what it does to your options. Keep Terraform and keep running it yourself, in Jenkins, GitHub Actions or Atlantis, and none of this reaches you: internal use is exactly what the BSL leaves alone, and Digger is open source too, so the self-hosted runners stay available. Go shopping for a hosted platform and the shelf is shorter than it was. Spacelift, env0 and Scalr can’t take you past the last open source release, and the hosted product that ships current Terraform belongs to the company that wrote the license.

Terragrunt is the cautionary tale on the other side. It began as a thin wrapper that linked in the Terraform binary and added a few shortcuts. Today it carries features vanilla Terraform doesn’t have, remote state lookups in plans among them, and once your code uses those, going back isn’t a swap.

The same trap is open in both directions now, though testing is the wrong example to reach for: OpenTofu shipped a test framework of its own in 1.6, in the same month Terraform 1.7 arrived. It’s the narrower features that pin you to a side. Terraform 1.7 added mocking on top of its test framework, which OpenTofu has no counterpart for, and OpenTofu will grow features Terraform has no counterpart for.

Swapping the binary was the easy half

So the decision is made for you. The work that follows is smaller than the dread around it.

How much work is a migration across hundreds of stacks?

Run terraform plan until it reports no changes, swap the binary, then run tofu init and tofu plan and compare. On 250 to 300 stacks that was effectively the whole procedure.

OpenTofu’s 1.6 migration guide asks for more than that. Step 0 is a disaster recovery plan you have tested, the state backup is step 3 and comes with a restore you have rehearsed at least once, and the guide closes with the steps for rolling back to Terraform. We didn’t rehearse recovery across 300 state files, and we won’t pretend otherwise: test the procedure on one or two stacks, then roll through the rest. Your appetite for that depends on what your stacks hold.

The real cost was housekeeping. At that number of stacks, some are broken at any given moment, and a clean plan is the precondition for the whole method. So the migration doubled as a cleanup: fix the stacks, confirm the plans are empty, then switch. Our Spacelift stacks are themselves managed in Terraform through the Spacelift provider, so flipping the binary was one field change, rolled out the way every other change is.

One thing bit us, and only in a couple of places. A few stacks pinned required_version in the terraform block tightly enough to exclude 1.6, and OpenTofu 1.6 reads that constraint and refuses to run. A constraint such as ~> 1.5.0 would do it, where the looser >= 1.5 and ~> 1.5 accept 1.6 and need no edit at all. Grep for the tight ones before you start. Past that, it just worked.

If you’re staying on Terraform for the moment, the practical advice is to stay off the features that have no OpenTofu equivalent, because those are the ones that turn a binary swap into a rewrite.

The module registry is the part that isn’t automatic

Compatibility of your own code is one question. Compatibility of everything you pull in is another, and it was the open worry when the fork was announced.

Will the modules and providers you depend on work on OpenTofu?

Ours did, and licensing is not what stands in the way: the relicensing covered HashiCorp’s own products, and OpenTofu’s FAQ says “Terraform providers have not altered their licenses”.

Unchanged licenses settle the legal question and leave the technical one, which you answer module by module. A module written against a feature only one binary has will fail for consumers running the other. We use few public modules by preference, running our own opinionated ones from a registry we built in-house, and nothing we pull in broke on the switch.

The catch we did hit is narrower than either. A bare registry source, the <NAMESPACE>/<NAME>/<PROVIDER> form with no hostname in front of it, resolves through OpenTofu’s public registry, and that registry is populated by submission rather than by mirroring everything. Prefix a hostname and the address goes to that registry instead, so a private registry is not part of this problem. The popular public modules are there. OpenTofu’s guidance is to check whether a missing module or provider exists in the Terraform registry and open an issue if it does, and getting yours listed means an issue on opentofu/registry from one of the templates the repository supplies: one for a module, one for a provider, one for a provider signing key. The OpenTofu team approves or denies each submission.

That is worth five minutes of your time if you publish modules. We checked ours during the recording and they aren’t listed, so a bare public registry address for them could fail to resolve for anyone who has moved to OpenTofu. Nothing warns you that the listing is missing. It’s a resolution problem rather than a compatibility one: every other source type still works, so a consumer can point source at the module’s Git URL and carry on.

There’s a case for the registry not copying everything blindly, too, though we’re guessing at the reasoning. What the repository promises is that submissions get reviewed, not that modules get tested, and waiting for a submission is at least a point where the maintainer has said the module belongs on this binary.

Your infrastructure runs beside the pipeline, not inside it

Adopting a TACOS changes more than which binary runs, and this part confuses teams used to end-to-end pipelines.

Where does the developer see their infrastructure change?

At TIER, nowhere inside the deployment pipeline. Spacelift watches the repository itself and runs beside the application build, triggered by its own path filters rather than by a stage in that pipeline.

The mental model most of us carry is one pipeline per commit: unit tests, Docker build, push to ECR, deploy, promote, and a developer who can point at the stage their change sits in. Spacelift isn’t in that sequence. You tell it which folders to track and write push policies deciding which file changes trigger a run. Change nothing under those paths and it stays quiet while your application pipeline ships as usual.

The workflow we grew out of looked like that too: deploy to staging, promote to production, with the infrastructure stacks running for both. Staging went away for an unrelated reason: some services there only looked like they worked, so at $25,000 a month it wasn’t worth keeping.

Decoupling costs you something real. Commit an application change and the database it needs in the same push and the two run concurrently, so the app can reach for a database that isn’t created yet. Ordering is work you do yourself: land the infrastructure change and let its run finish before the application change ships.

Visibility is a different question from ordering. In GitLab CI the Spacelift plans show up as jobs inside your pipeline, so a developer sees the infrastructure run from the same place they see the build. With GitHub Actions and CircleCI it didn’t work the same way, as far as we could tell.

The exception is the setup where your software orchestrator and your cloud API are the same API. On ECS or Lambda, deploying a new version is an AWS call of the same kind Terraform makes, and the temptation is to do infrastructure and release in one apply. Split the version switch out: update the task definition or the function’s package with the AWS CLI. Splitting the call isn’t enough on its own, because your configuration still claims the attribute the pipeline just changed, and the next apply plans it back. Hand that attribute over with ignore_changes: ignore_changes = [task_definition] on the ECS service once the release pipeline owns the revision. With Kubernetes the split is drawn for you: the cluster has its own API, and Helm or Argo CD talks to it.

Policies do the babysitting

Once infrastructure runs on its own track, the question is who approves what, and this is where the platform earns its cost.

What stops a developer breaking production through the infrastructure repo?

Rules evaluated against the plan, before the apply, rather than a person reading every diff.

Spacelift’s policies are Rego, evaluated by Open Policy Agent at several decision points. Plan policies decide which changes can be applied at all, push policies interpret Git events, trigger policies chain stacks when one finishes, notification policies route the result to Slack or a webhook. The ones that changed our week were the plan policies: deleting a Vault secret or a database is refused outright, and a defined set of changes needs an approval from somebody else on the developer’s own team rather than from us.

The reason this is worth doing is not governance theatre. You trust developers, and they still don’t always have the context to know which change is safe. Before policies, we approved those changes by hand, which meant we were in the path of every one of them.

The same rules make automation safe elsewhere. Spacelift’s drift detection runs plans on a cron and can open reconciliation runs by itself, and those runs are ordinary tracked runs, so they go through the stack’s plan policies like anything else. On the stacks that change constantly we reconcile every 15 minutes without worrying much, because the policy is what stands between a reconciliation and a deleted database.

Visibility is the quieter half of the same argument. The resource view reads the state file and shows what’s deployed and the real ID of each resource, which is how you answer “did that actually apply” without scrolling a plan log, and sanitization keeps Vault secrets out of it once developers have access.

Trigger policies do the rest of the job. Our service registry would be one enormous stack if it managed everything, so it’s split into stacks for teams, alerting infrastructure and Okta identities, chained by triggers that fire as each one finishes.

Who owns the worker owns what you can build

Policies are the governance argument for a platform. The worker is the engineering one, and it decides what your configuration is allowed to assume.

Why does it matter whose machine the plan runs on?

Because the hosted worker is somebody else’s container, and anything your configuration needs that isn’t already in it has to be carried in on terms the vendor sets.

Terraform Cloud is explicit about those terms. The documentation says it “does not allow you to elevate a command’s permissions with sudo during Terraform runs”, that you “can install and execute standalone binaries in Terraform’s working directory”, and that whenever possible you shouldn’t install software on the worker at all, because the worker is disposable and its operating system isn’t promised to stay the same. That’s a defensible position when you hold other people’s secrets, since arbitrary code next to those credentials is a short path to exfiltration. It’s still a boundary your modules have to live inside.

We hit it from the publishing side. Some of the modules we maintain build a Python Lambda with its dependencies, and a user reported they couldn’t run one: the Python version they needed wasn’t on the worker, and Docker apparently isn’t available there either. The fix we’re heading for is to pre-build the zip files, publish them to a CDN and make that the default, with a build-it-yourself fallback.

Private workers widen the same boundary. Terraform isn’t the right tool for complicated data transformation, and mapping teams to services to stacks to Kubernetes roles was three layers of nested for loops before we gave up and wrote it in Go. That binary runs on our own worker before the plan, produces the data, and Tofu takes it from there. Hosted, it has to be a standalone binary vendored into the working directory, on a machine the documentation would rather you left alone. On a worker you own, it’s part of the image.

Local previews come from the same place. spacectl stack local-preview uploads your working directory to a worker and runs the plan there, so you iterate without committing and without a Terraform binary of your own. Our developers can’t assume the role that would let them run anything locally, which is deliberate: IAM on that role is what decides who can change infrastructure. Denying access to the state bucket is the cheaper, weaker version. It blocks the shared-state workflow and nothing else, since a local backend keeps state on disk and a direct API call skips state entirely.

What this means for teams

If a vendor runs Terraform for you and sells a service HashiCorp competes with, your version ceiling is set by a license you didn’t sign, and the gap only widens from here. Run it in your own pipeline instead and the license leaves you alone, which is its own trade: you keep the versions, you keep the maintenance. The migration itself is a binary swap on top of a clean plan. The expensive parts are the cleanup you’ve been deferring and the features you adopt in the meantime that have no equivalent on the other side.

The second lesson has nothing to do with the fork. Moving infrastructure onto its own track changes how your developers see their changes and who sequences what, and the platform you pick decides which guardrails you can express and what your plans are allowed to run. Both of those are harder to reverse than the binary.

This week:

  • Run terraform plan across every stack and count how many are already broken. That identifies the cleanup you need before comparing plans.
  • Grep your terraform blocks for required_version constraints that exclude 1.6, such as ~> 1.5.0 where ~> 1.5 was meant.
  • If you publish modules, check whether they resolve in the OpenTofu registry, and submit the ones that don’t.
  • Write down one change your platform should refuse outright, deleting a database or a secret, and put it in a plan policy instead of an approval queue.

Common questions, answered

How do I switch a Terraform stack to OpenTofu without breaking the state?

Get terraform plan to report no changes, back up the state file, then run tofu init, run tofu plan and compare. A matching empty plan on both sides means nothing moved.

Do a stack or two by hand first. OpenTofu’s 1.6 migration guide opens with a disaster recovery plan you have tested, puts the state backup at step 3, and ends with instructions for rolling back to Terraform. The one edit you may need is a required_version constraint that excludes 1.6: ~> 1.5.0 stops OpenTofu 1.6 before it starts, while >= 1.5 and ~> 1.5 are fine.

Why can’t my Terraform automation vendor install a newer Terraform version?

Because the Business Source License stops vendors who sell a competing service from shipping releases published after the change, so their newest supported Terraform is the last one under the old license.

Support can’t fix this. HashiCorp’s announcement says those vendors “will no longer be able to incorporate future releases, bug fixes, or security patches”, and its licensing FAQ leaves internal use alone, with custom terms available beyond that. On Spacelift, that left TIER two live options: stay on 1.5.7, or move to OpenTofu.

How do I use my own module on OpenTofu if it isn’t in the registry?

Point the source argument at the module’s Git URL instead of its registry address, which needs nobody’s approval.

Git sources bypass registry listings. A registry address does not: the module has to exist in whichever registry the address selects, and putting a hostname in front picks a different registry rather than skipping the listing. Git URLs, local paths, HTTPS archives and object storage resolve as they always did. The longer-term fix is a submission to opentofu/registry through its issue template. Private in-house registries are the other answer, and the one we use: limiting what developers reach for is the point.

Resources

Since we recorded

State encryption stopped being an alpha feature: OpenTofu 1.7.0 shipped on 30 April 2024 with encryption, provider-defined functions and removed blocks. The testing gap closed from the other side too, with provider mocking and resource overrides arriving in OpenTofu 1.8. The corporate owner on the other side changed, with IBM completing its acquisition of HashiCorp on 27 February 2025. We came back to the question twice: #83 OpenTofu vs Terraform: Where We Are Now with Cole Bittel checks how adoption actually went, and #85 Is It Time for OpenTofu? weighs it against the Terraform features that have since landed behind HCP Terraform.