Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opentofu: plugins not found due to missing registry override #283015

Open
KiaraGrouwstra opened this issue Jan 22, 2024 · 10 comments
Open

opentofu: plugins not found due to missing registry override #283015

KiaraGrouwstra opened this issue Jan 22, 2024 · 10 comments

Comments

@KiaraGrouwstra
Copy link
Contributor

Describe the bug

opentofu.withPlugins still fails to override registry.terraform.io to registry.opentofu.org.
as a result of this, it will fail to find used plugins, searching in a nix store path containing registry.terraform.io rather than registry.opentofu.org.

Steps To Reproduce

Steps to reproduce the behavior:

  1. use opentofu.withPlugins

  2. use a plugin in a .tf, e.g.:

    terraform {
      required_providers {
        nomad = {
          source = "hashicorp/nomad"
        }
      }
    }
    
    provider "nomad" {
      address = "http://127.0.0.1:4646"
    }
  3. run tofu init

  4. find error not unlike:

    │ Error: Failed to query available provider packages
    │ 
    │ Could not retrieve the list of available versions for provider hashicorp/nomad: provider registry.opentofu.org/hashicorp/nomad was not found in any of
    │ the search locations
    │ 
    │   - /nix/store/gaybr4b1wqlkfyppd0bnb0qwszki3az5-opentofu-1.6.0-rc1/libexec/terraform-providers
    

Expected behavior

plugins work using opentofu as well

Screenshots

Additional context

  • note this technically applies to both withPlugins as well as its derivatives like full and passthru.
  • while a workaround might be patching this to straight-up override the plugin domains, it would be nice to get a proper solution here i.e. that would not break the plugins for terraform.

Notify maintainers

@gmemstr
@NickCao
@zowoq

Metadata

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.7.0-zen2, NixOS, 24.05 (Uakari), 24.05.20240114.dd5621d`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.1`
 - channels(kiara): `"home-manager"`
 - channels(root): `""`
 - nixpkgs: `/nix/store/sl31dgnpwinzvzhh7ak2rx3h6w7kbb30-source`
@NickCao
Copy link
Member

NickCao commented Jan 22, 2024

A workaround is to specify the full path of the plugin, e.g. source = "registry.terraform.io/hashicorp/nomad".

@NickCao
Copy link
Member

NickCao commented Jan 23, 2024

Do you know about the current status of the opentofu registry? Is is a mirror of the terraform registry or something else?

@adamcstephens
Copy link
Contributor

They have a separate submission process, so it must not be just a mirror: https://github.com/opentofu/registry/tree/main#adding-providers-modules-or-gpg-keys-to-the-opentofu-registry

@NickCao
Copy link
Member

NickCao commented Jan 23, 2024

A workaround is to specify the full path of the plugin, e.g. source = "registry.terraform.io/hashicorp/nomad".

Then I would propose this as a solution (instead of just a workaround).

@KiaraGrouwstra
Copy link
Contributor Author

hm, long-term that would seem a bit like making opentofu a second-class citizen in nixpkgs, whereas it would seem more likely given its license and broad backing it will outlive terraform

@NickCao
Copy link
Member

NickCao commented Jan 23, 2024

hm, long-term that would seem a bit like making opentofu a second-class citizen in nixpkgs, whereas it would seem more likely given its license and broad backing it will outlive terraform

Having a default registry other than it's own is not making it a second-class citizen. Take podman as an example, despite having it's own (partly so) registry quay.io, still mostly uses docker.io as the default.

@KiaraGrouwstra
Copy link
Contributor Author

opentofu seems to use its own registry by default rather than terraform's

@Sorixelle
Copy link
Member

Unfortunately, it seems like OpenTofu doesn't have a choice - the Terraform Registry's ToS doesn't allow OpenTofu to use it (source).

It doesn't look like we're downloading providers from the registry, so we shouldn't be running afoul of that clause. We just need to use a different folder name for Terraform (registry.terraform.io) and OpenTofu (registry.opentofu.org). I don't think that's impossible to implement (at least, after a brief glance at the terraform-providers implementation).

@zowoq
Copy link
Contributor

zowoq commented Feb 7, 2024

#269106

I've got a draft PR that will drop the terraform registry in favour of just using the provider github repos directly, it'll be simple to include an option to use either registry.terraform.io or registry.opentofu.org in that PR.

I plan to finish the PR sometime in the next few weeks.

@yajo
Copy link
Contributor

yajo commented Mar 20, 2024

A workaround I found for now, which implies rebuilding the providers:

{
  lib,
  opentofu,
}: let
  # HACK https://github.com/NixOS/nixpkgs/issues/283015
  tofuProvider = provider:
    provider.override (oldArgs: {
      provider-source-address =
        lib.replaceStrings
        ["https://registry.terraform.io/providers"]
        ["registry.opentofu.org"]
        oldArgs.homepage;
    });
in
  opentofu.withPlugins (ps:
    builtins.map tofuProvider [
      ps.aws
      ps.hcloud
    ])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants