Skip to content

A simple example to switch from Terraform to OpenTofu in a CDKTF stack

License

Notifications You must be signed in to change notification settings

therealvio/cdktofu-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cdktofu-example

A simple example to switch from Terraform to OpenTofu in a CDKTF stack.

The code within this repository is based on the generated template from cdktf init running version 0.20.10 with some minor changes that don't impact the the outcome of the example.

For a change-by-change example, check out this PR.

Switching from Terraform to OpenTofu

This guide assumes you have OpenTofu installed

Using the OpenTofu binary

In most cases you only need to set the TERRAFORM_BINARY_NAME environment variable to the value "tofu". Once this is done, you can verify this by checking the cdktf output. What you should see if OpenTofu in place of Terraform, as depicted in the screenshot below.

screenshot of cdktf CLI output showing the use of OpenTofu in place of Terraform

In this example repo, this is set in an .envrc file so tools like direnv can reference it.

Updating Providers

Note

If your project only uses the pre-built providers, this isn't applicable to you.

If you generate your own providers within your project is configured in cdktf.json that uses the hardcoded registry.terraform.io registry, OpenTofu can fail to resolve the provider. To address this, it's a matter of adding the OpenTofu registry as a prefix to your provider in cdktf.json. Refer to the example below.

-"terraformProviders": ["cloudflare/cloudflare@4.49.1"],
+"terraformProviders": ["registry.opentofu.org/cloudflare/cloudflare@4.49.1"],

About

A simple example to switch from Terraform to OpenTofu in a CDKTF stack

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published