Terraform to opentofu help

i’m having some issues migrating to opentofu when using some providers

in my current example i’m using hetznercloud/hcloud and tls providers and the relevant configuration (json instead of hcl):

  "terraform": {
    "required_providers": {
      "hcloud": {
        "source": "hetznercloud/hcloud",
        "version": ">= 1.44.0"
      }
    }
  }

and the error i get when i run tofu init

$ tofu init

Initializing the backend...

Initializing provider plugins...
- Finding hetznercloud/hcloud versions matching ">= 1.44.0"...
- Finding latest version of hashicorp/tls...
╷
│ Error: Failed to query available provider packages
│ 
│ Could not retrieve the list of available versions for provider hetznercloud/hcloud: provider registry.opentofu.org/hetznercloud/hcloud was
│ not found in any of the search locations
│ 
│   - /nix/store/hdddlh2r2cwfwskx6y5j4znwxnv3zc3g-opentofu-1.6.2/libexec/terraform-providers
╵

╷
│ Error: Failed to query available provider packages
│ 
│ Could not retrieve the list of available versions for provider hashicorp/tls: provider registry.opentofu.org/hashicorp/tls was not found
│ in any of the search locations
│ 
│   - /nix/store/hdddlh2r2cwfwskx6y5j4znwxnv3zc3g-opentofu-1.6.2/libexec/terraform-providers
╵

i checked and hcloud is in the opentofu registry (ref), assuming that is important for a nixpkgs provided opentofu binary

this is the nix expression from my dev shell:

pkgs.opentofu.withPlugins (p: [ p.hcloud p.tls ])

any and all help is greatly appreciated

Try this instead?

{
  "terraform": {
    "required_providers": {
      "hcloud": {
        "source": "registry.terraform.io/hetznercloud/hcloud",
        "version": ">= 1.44.0"
      }
    }
  }
}

AFAIK only the terraform version is packaged: https://github.com/NixOS/nixpkgs/blob/614b4613980a522ba49f0d194531beddbb7220d3/pkgs/applications/networking/cluster/terraform-providers/providers.json#L512-L520

we only have terraform versions for all providers - so i need to specify the (terraform) registry for everything?

thanks, very helpful, i think this all makes sense to me now

Yes, I only see providers from the terraform registry on nixpkgs, and since opentofu defaults to its own registry (as it should), we are forced to specify it.

Not sure if in the future we will have a mix of terraform and opentofu providers, in case of doubt you can manually check the search locations, in your case /nix/store/hdddlh2r2cwfwskx6y5j4znwxnv3zc3g-opentofu-1.6.2/libexec/terraform-providers and you will see a folder structure that starts with the registry name.