summaryrefslogtreecommitdiffstats
path: root/pkgs/applications/networking/cluster/terraform
diff options
context:
space:
mode:
authorTimothy Stott <stott.timothy@gmail.com>2020-10-05 23:52:33 +0100
committerTimothy Stott <stott.timothy@gmail.com>2020-10-08 22:18:12 +0100
commitcd1b59476793278191c37572c8081b856512eec4 (patch)
treea6da249b3383aba1dec8d8e189d25856ff5c5197 /pkgs/applications/networking/cluster/terraform
parent72cd428dd20d6407ebceec9cb8bedaef908e56e4 (diff)
terraform: expose providers to terraform 0.13
Terraform 0.13 adopts a new filesystem layout for plugins (illustrated below). Terraform 0.12 and earlier `plugins-dir/terraform-provider-aws_v3.7.0` Terraform 0.13 `plugins-dir/registry.terraform.io/hashicorp/aws/3.7.0/linux_amd64/terraform-provider-aws_v3.7.0` To support all packaged Terraform versions a shim is created at both locations. This approach was inspired by https://github.com/numtide/generate-terraform-provider-shim Terraform 0.13 provider documentation https://www.terraform.io/upgrade-guides/0-13.html#new-filesystem-layout-for-local-copies-of-providers layout terraform providers filesystem in withPlugins
Diffstat (limited to 'pkgs/applications/networking/cluster/terraform')
-rw-r--r--pkgs/applications/networking/cluster/terraform/default.nix34
1 files changed, 26 insertions, 8 deletions
diff --git a/pkgs/applications/networking/cluster/terraform/default.nix b/pkgs/applications/networking/cluster/terraform/default.nix
index b531055a1bfc..5f2ef78b495b 100644
--- a/pkgs/applications/networking/cluster/terraform/default.nix
+++ b/pkgs/applications/networking/cluster/terraform/default.nix
@@ -1,5 +1,5 @@
{ stdenv, lib, buildEnv, buildGoPackage, fetchFromGitHub, makeWrapper, coreutils
-, runCommand, writeText, terraform-providers, fetchpatch }:
+, runCommand, runtimeShell, writeText, terraform-providers, fetchpatch }:
let
goPackagePath = "github.com/hashicorp/terraform";
@@ -59,6 +59,29 @@ let
let
actualPlugins = plugins terraform.plugins;
+ # Make providers available in Terraform 0.13 and 0.12 search paths.
+ pluginDir = lib.concatMapStrings (pl: let
+ inherit (pl) repo version GOOS GOARCH;
+ inherit (pl.passthru) providerSourceAddress;
+
+ shim = writeText "shim" ''
+ #!${runtimeShell}
+ exec ${pl}/bin/${repo}_v${version} \$@
+ '';
+ in ''
+ TF_0_13_PROVIDER_PATH=$out/plugins/${providerSourceAddress}/${version}/${GOOS}_${GOARCH}/${repo}_v${version}
+ mkdir -p "$(dirname $TF_0_13_PROVIDER_PATH)"
+
+ cp ${shim} "$TF_0_13_PROVIDER_PATH"
+ chmod +x "$TF_0_13_PROVIDER_PATH"
+
+ TF_0_12_PROVIDER_PATH=$out/plugins/${repo}_v${version}
+
+ cp ${shim} "$TF_0_12_PROVIDER_PATH"
+ chmod +x "$TF_0_12_PROVIDER_PATH"
+ ''
+ ) actualPlugins;
+
# Wrap PATH of plugins propagatedBuildInputs, plugins may have runtime dependencies on external binaries
wrapperInputs = lib.unique (lib.flatten
(lib.catAttrs "propagatedBuildInputs"
@@ -87,15 +110,10 @@ let
inherit (terraform) name;
buildInputs = [ makeWrapper ];
- buildCommand = ''
+ buildCommand = pluginDir + ''
mkdir -p $out/bin/
makeWrapper "${terraform}/bin/terraform" "$out/bin/terraform" \
- --set NIX_TERRAFORM_PLUGIN_DIR "${
- buildEnv {
- name = "tf-plugin-env";
- paths = actualPlugins;
- }
- }/bin" \
+ --set NIX_TERRAFORM_PLUGIN_DIR $out/plugins \
--prefix PATH : "${lib.makeBinPath wrapperInputs}"
'';