opentofu: Allow using terraform-providers.* from binary cache
Currently `opentofu.withPlugins(p: [p.<plugin>])` causes `<plugin>` to rebuild. Since we build terraform-providers.* from source, overriding homepage of terraform-providers.* only affects their `postInstall` phase, the providers binaries remain the same. We can avoid the provider rebuilds by creating the right dir in the wrapper.
This commit is contained in:
@@ -108,28 +108,7 @@ let
|
||||
withPlugins =
|
||||
plugins:
|
||||
let
|
||||
actualPlugins = lib.lists.map (
|
||||
provider:
|
||||
if provider ? override then
|
||||
# use opentofu plugin registry over terraform's
|
||||
provider.override (
|
||||
oldArgs:
|
||||
if (builtins.hasAttr "homepage" oldArgs) then
|
||||
{
|
||||
provider-source-address =
|
||||
lib.replaceStrings
|
||||
[ "https://registry.terraform.io/providers" ]
|
||||
[
|
||||
"registry.opentofu.org"
|
||||
]
|
||||
oldArgs.homepage;
|
||||
}
|
||||
else
|
||||
{ }
|
||||
)
|
||||
else
|
||||
provider
|
||||
) (plugins package.plugins);
|
||||
actualPlugins = plugins package.plugins;
|
||||
|
||||
# Wrap PATH of plugins propagatedBuildInputs, plugins may have runtime dependencies on external binaries
|
||||
wrapperInputs = lib.unique (
|
||||
@@ -183,13 +162,16 @@ let
|
||||
passthru = package.passthru // passthru;
|
||||
|
||||
buildCommand = ''
|
||||
# Create wrappers for terraform plugins because Terraform only
|
||||
# Create wrappers for terraform plugins because OpenTofu only
|
||||
# walks inside of a tree of files.
|
||||
# Also replace registry.terraform.io dir with registry.opentofu.org,
|
||||
# so OpenTofu can find the plugins.
|
||||
for providerDir in ${toString actualPlugins}
|
||||
do
|
||||
for file in $(find $providerDir/libexec/terraform-providers -type f)
|
||||
do
|
||||
relFile=''${file#$providerDir/}
|
||||
relFile=''${relFile/registry.terraform.io/registry.opentofu.org}
|
||||
mkdir -p $out/$(dirname $relFile)
|
||||
cat <<WRAPPER > $out/$relFile
|
||||
#!${runtimeShell}
|
||||
|
||||
Reference in New Issue
Block a user